1. Introduction
TFTP is a very simple protocol used to transfer files. It is from this that its name comes, Trivial File Transfer Protocol or TFTP. It has been implemented on top of the Internet User Datagram protocol (UDP or Datagram).
2. 5 types of Datagrams
They are Read request(RRQ), Write request(WRQ), Data(DATA), ACK(ACK) and Error(ERROR).
Here is the structure of these 5 datagrams.
OPCODE: 2 Bytes. Indicate which type the datagram belongs to.
Other information in the datagram depends on the type of the datagram.
2.1 RRQ
2.2 WRQ
mode: Indicate which kind of method the transportation is using, netascii or octet.
if netascii, you must be aware that: In Windows, it's '\r\n' that returns, while in Unix, it's '\r'. if octet, there is no need in doing these.
2.3 DATA
2.4 ACK
When TFTP session begins, there is no field in the datagram that indicates the length of the file. Then how the sender indicate the end of the file? TFTP uses a special way to indicate this, though it has a flaw(We will see later).
Data block = 512 Bytes
When Data block = 0-511, it is the last block of the file.
2.5 ERROR
TFTP error code:
0- not defined
1- File not found
2- Access violation
3- Disk full
4- Illegal TFTP operation
5- Unknown port
6- File already exists
7- No such user
3. File Transport
3.1 Read File
3.2 Write File
4. Error Handling
TFTP offers a stop-and-wait way to dispose of situations when an error happens.
For example, when a client reads a file from a server, it will send an RRQ. Then some error happens and no ack will be received from the server, so the client will wait forever. However, if the client sets a timeout for each RRQ it sends to the server, such dilemma as above would be avoided.
5. Questions
- To test the program, we need to create these errors: no send? no ack? how?
- If a server has more than 2 clients(this is no wonder)?
- Be careful with these file with size=0, size%512=0.
- Block size = 512? Really so? Could block size be negotiated between the server and the client?
- Timeout set to 5 seconds? What value is appropriate? Could the timeout value be adjusted dynamically?
- If the client resend it's RRQ or WRQ, what should we do?
6. Conclusion & Further work
This is a small but interesting project, accomplishable both in Windows and in Unix. After we have dealt with all the problems in Section 5, we can actually do many other things. For example, there are many other options in TFTP we can implement(see RFC 2347), and we can also create a simple UI for the protocol. Moreover, we can employ an access control on the clients(IP, authorization, access time).
7. Reference Materials
- RFC 1350: Trivial File Transfer Protocol
- RFC 2347: TFTP Option Extension
- RFC 2348: TFTP Blocksize Option
- RFC 2349: TFTP Timeout Interval and Transfer Size Options