What is TFTP, this article will take you to understand

Table of contents

1. Introduction to TFTP protocol

The main features of the TFTP protocol include:

2. TFTP packet format

1. Read/write request packet

2. File Packet

3. Response packet

4. Error information package

3. The workflow of TFTP

The workflow of the TFTP protocol includes the following steps:

Four, TFTP transmission mode

1. Binary transfer mode

2. ASCII code transmission mode

Summarize


1. Introduction to TFTP protocol

 

TFTP (Trivial File Transfer Protocol) is a simple file transfer protocol, which is implemented on the basis of UDP (User Datagram Protocol) protocol. The TFTP protocol was originally defined by RFC (Request for Comments) 783, and its main purpose is to transfer files quickly and easily on the network. The TFTP protocol is mainly used in scenarios such as network booting and configuration file transmission. It is characterized by simplicity, light weight, and easy implementation.

The main features of the TFTP protocol include:

1. The TFTP protocol uses the UDP protocol for data transmission, so its data transmission efficiency is relatively low, but its implementation is very simple.

2. The data transmission of the TFTP protocol is based on data blocks, and the size of each data block is 512 bytes.

3. The TFTP protocol supports both read and write operations. The read operation is used to download files from the server, and the write operation is used to upload files to the server.

4. The TFTP protocol supports error handling. When an error occurs, the TFTP protocol will send an error message to the other party.

2. TFTP packet format

The TFTP protocol defines four data packet formats, which are read/write request packets, file data packets, response packets, and error information packets. Let's introduce the formats of these four packets one by one.

1. Read/write request packet

The read/write request packet is the most commonly used data packet in the TFTP protocol, and it is used to initiate a read/write operation. The format of the read/write request packet is as follows:

```
  2 bytes     string    1 byte     string   1 byte
  ------------------------------------------------
 | Opcode |  Filename  |   0  |    Mode    |   0  |
  ------------------------------------------------
```

Among them, Opcode represents the operation code, and its value is 1 for read operation and 2 for write operation; Filename represents the file name, which is a string ending with 0; Mode represents the transmission mode, which is also a string ending with 0 , commonly used transmission modes are "octet" (binary transmission) and "netascii" (ASCII code transmission).

2. File Packet

The file data packet is used to transmit file data, and its format is as follows:

```
  2 bytes     2 bytes      n bytes
  ----------------------------------
 | Opcode |   Block #  |   Data     |
  ----------------------------------
```

Among them, Opcode represents the operation code, and its value is 3; Block # represents the data block number, and its value increases from 1; Data represents the content of the data block, and its length is 512 bytes.

3. Response packet

The response packet is used to send response information to the other party, and its format is as follows:

```
  2 bytes     2 bytes      n bytes
  ----------------------------------
 | Opcode |   Block #  |   Data     |
  ----------------------------------
```

Among them, Opcode represents the operation code, and its value is 4; Block # represents the data block number, and its value is the same as the data block number of the file data packet sent by the other party; Data represents the content of the response message, and its length is not fixed.

4. Error information package

The error information packet is used to send error information to the other party, and its format is as follows:

```
  2 bytes     2 bytes      n bytes
  ----------------------------------
 | Opcode |  ErrorCode |   ErrMsg   |  0 |
  ----------------------------------
```

Among them, Opcode represents the operation code, and its value is 5; ErrorCode represents the error code, and its value ranges from 0 to 7. The specific meanings are as follows:

- 0: Undefined error
- 1: File does not exist
- 2: Access is denied
- 3: Disk full
- 4: Operation timed out -
5: File transfer interrupted
- 6: Unknown transfer ID
- 7: File already exists

ErrMsg indicates the content of the error message, which is a 0-terminated string.

3. The workflow of TFTP

 

The workflow of the TFTP protocol includes the following steps:

1. The client sends a read/write request packet to the server.

2. After receiving the read/write request packet, the server opens the corresponding file according to the file name and transmission mode in the request packet, and sends the first data block to the client.

3. After receiving the file data packet, the client sends a response packet to the server to confirm receipt of the data block.

4. After the server receives the response packet, it continues to send the next data block to the client until the file transfer is completed.

5. If an error occurs during transmission, the server will send an error packet to the client, and the transmission process will be interrupted.

Four, TFTP transmission mode

The TFTP protocol supports two transmission modes, namely the binary transmission mode and the ASCII code transmission mode.

1. Binary transfer mode

 

The binary transfer mode is the default transfer mode of the TFTP protocol, which is suitable for transferring binary files, such as programs, pictures, audio, etc. In the binary transmission mode, the TFTP protocol does not perform any conversion on the data, and directly transmits the data block to the other party.

2. ASCII code transmission mode

 

The ASCII code transfer mode is suitable for transferring text files, such as configuration files and script files. In the ASCII code transmission mode, the TFTP protocol will convert the newline characters in the data block to local newline characters, and remove the spaces at the end of the file.

Summarize

The TFTP protocol is a simple and lightweight file transfer protocol. Its main features are simple implementation and easy deployment. The data transfer efficiency of the TFTP protocol is relatively low, but its implementation is very simple, and it is suitable for some simple file transfer scenarios. The workflow of the TFTP protocol includes steps such as read/write requests, file data transmission, response, and error handling. It supports two transmission modes: binary transmission and ASCII code transmission.

Guess you like

Origin blog.csdn.net/weixin_74021557/article/details/131260340