1. TFTP protocol Introduction
TFTP (Trivial file Transfer Protocol, simple Document Transfer Protocol)
is a protocol in the family of TCP/IP protocols for simple file transfer between client and server
Characteristics:
- Simple
- Low resource footprint
- Suitable for passing small files
- Suitable for on-LAN delivery
- Port number is 69
- Based on UDP implementation
2. TFTP download process
TFTP server listens on port 69th by default
When a client sends a "download" request (that is, a read request), it needs to send a 69 port to the server
If the server approves this request, it uses a new, temporary port for data transfer
When the server finds a file that needs to be present, it immediately opens the file and sends the data in the file to the client via the TFTP protocol.
If the total size of the file is large (for example, 3M), then the server is sent multiple times, each time it reads 512 bytes of data from the file.
Because the number of times sent can be many, so in order to let the client docking the received data to sort, so when the server sends the 512 bytes of data, there will be more than 2 bytes of data, used to store the ordinal number, and placed in front of 512 bytes of data, the sequence number is starting from 1
Because the file may not exist when the file needs to be downloaded from the server, the server will send an error message, in order to differentiate the service is sending the file content or the wrong message, so it uses 2 bytes to represent the function of the packet (called OpCode), and in the front of the ordinal
Note: 1. Packet format is in string form
2. Need to indicate the size of the end
3. The memory size in which the packet is defined needs to be formatted with a struct module
Python Socket TFTP protocol