TFTP: Trivial File Transfer Protocol

Trivial File Transfer Protocol (TFTP) is a simple protocol to transfer files. It has been implemented on top of the User Datagram Protocol (UDP) using port number 69. TFTP is designed to be small and easy to implement, therefore, lacks most of the features of a regular FTP. TFTP only reads and writes files (or mail) from/to a remote server. It cannot list directories, and currently has no provisions for user authentication.

In TFTP, any transfer begins with a request to read or write a file, which also serves to request a connection. If the server grants the request, the connection is opened and the file is sent in fixed length blocks of 512 bytes. Each data packet contains one block of data, and must be acknowledged by an acknowledgment packet before the next packet can be sent. A data packet of less than 512 bytes signals termination of a transfer. If a packet gets lost in the network, the intended recipient will timeout and may retransmit his last packet (which may be data or an acknowledgment), thus causing the sender of the lost packet to retransmit that lost packet. The sender has to keep just one packet on hand for retransmission, since the lock step acknowledgment guarantees that all older packets have been received. Notice that both machines involved in a transfer are considered senders and receivers. One sends data and receives acknowledgments, the other sends acknowledgments and receives data.

Three modes of transfer are currently supported by TFPT: netascii, that it is 8 bit ascii; octet (This replaces the "binary" mode of previous versions of this document.) raw 8 bit bytes; mail, netascii characters sent to a user rather than a file. Additional modes can be defined by pairs of cooperating hosts.

The current version of TFTP is version 2 (TFTPv2).

Protocol Structure - TFTP: Trivial File Transfer Protocol

The header structures of TFTP messages/packets:

RRQ/WRQ packet:

2 bytes String 1 byte String 1 byte
Opcode Filename 0 Mode 0

 

Opcode - Operation code or commands. The following are TFTP commands:

Opcode Command Description
1 Read Request Request to read a file.
2 Write Request Request to write to a file.
3 File Data Transfer of file data.
4 Data Acknowledge Acknowledgement of file data.
5 Error Error indication.

 

Filename - The to be transferred file name.

Mode - Datamode. The format of the file data that the protocol is to transfer. It could be NetASCII Standard ASCII, Octet Eight-bit binary data, or Mail Standard ASCII.

Data packet:

2 bytes 2 bytes 0-512 bytes
Opcode Block # Data

 

The Opcode is 3.

Block # - Block numbers on data packets begin with one and increase by one for each new block of data.

Data - Data field range from 0 to 512 bytes.

ACK packet:

2 bytes 2 bytes
Opcode Block #

 

The Opcode is 4.

Block# - Block number echoes the block number of the DATA packet being acknowledged.

A WRQ is acknowledged with an ACK packet having a block number of zero.

Error Packet:

2 bytes 2 bytes String 1 byte
Opcode Error ErrMsg 0

 

The Opcode is 5.

Error code - an integer indicating the nature of the error.
0         Not defined, see error message (if any).
1         File not found.
2         Access violation.
3         Disk full or allocation exceeded.
4         Illegal TFTP operation.
5         Unknown transfer ID.
6         File already exists.
7         No such user.

ErrMSG - Error message is intended for human consumption, and should be in netascii.  It is terminated with a zero byte.

添加新评论