Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

603 lines
24 KiB

  1. Network Working Group K. Sollins
  2. Request For Comments: 1350 MIT
  3. STD: 33 July 1992
  4. Obsoletes: RFC 783
  5. THE TFTP PROTOCOL (REVISION 2)
  6. Status of this Memo
  7. This RFC specifies an IAB standards track protocol for the Internet
  8. community, and requests discussion and suggestions for improvements.
  9. Please refer to the current edition of the "IAB Official Protocol
  10. Standards" for the standardization state and status of this protocol.
  11. Distribution of this memo is unlimited.
  12. Summary
  13. TFTP is a very simple protocol used to transfer files. It is from
  14. this that its name comes, Trivial File Transfer Protocol or TFTP.
  15. Each nonterminal packet is acknowledged separately. This document
  16. describes the protocol and its types of packets. The document also
  17. explains the reasons behind some of the design decisions.
  18. Acknowlegements
  19. The protocol was originally designed by Noel Chiappa, and was
  20. redesigned by him, Bob Baldwin and Dave Clark, with comments from
  21. Steve Szymanski. The current revision of the document includes
  22. modifications stemming from discussions with and suggestions from
  23. Larry Allen, Noel Chiappa, Dave Clark, Geoff Cooper, Mike Greenwald,
  24. Liza Martin, David Reed, Craig Milo Rogers (of USC-ISI), Kathy
  25. Yellick, and the author. The acknowledgement and retransmission
  26. scheme was inspired by TCP, and the error mechanism was suggested by
  27. PARC's EFTP abort message.
  28. The May, 1992 revision to fix the "Sorcerer's Apprentice" protocol
  29. bug [4] and other minor document problems was done by Noel Chiappa.
  30. This research was supported by the Advanced Research Projects Agency
  31. of the Department of Defense and was monitored by the Office of Naval
  32. Research under contract number N00014-75-C-0661.
  33. 1. Purpose
  34. TFTP is a simple protocol to transfer files, and therefore was named
  35. the Trivial File Transfer Protocol or TFTP. It has been implemented
  36. on top of the Internet User Datagram protocol (UDP or Datagram) [2]
  37. Sollins [Page 1]
  38. RFC 1350 TFTP Revision 2 July 1992
  39. so it may be used to move files between machines on different
  40. networks implementing UDP. (This should not exclude the possibility
  41. of implementing TFTP on top of other datagram protocols.) It is
  42. designed to be small and easy to implement. Therefore, it lacks most
  43. of the features of a regular FTP. The only thing it can do is read
  44. and write files (or mail) from/to a remote server. It cannot list
  45. directories, and currently has no provisions for user authentication.
  46. In common with other Internet protocols, it passes 8 bit bytes of
  47. data.
  48. Three modes of transfer are currently supported: netascii (This is
  49. ascii as defined in "USA Standard Code for Information Interchange"
  50. [1] with the modifications specified in "Telnet Protocol
  51. Specification" [3].) Note that it is 8 bit ascii. The term
  52. "netascii" will be used throughout this document to mean this
  53. particular version of ascii.); octet (This replaces the "binary" mode
  54. of previous versions of this document.) raw 8 bit bytes; mail,
  55. netascii characters sent to a user rather than a file. (The mail
  56. mode is obsolete and should not be implemented or used.) Additional
  57. modes can be defined by pairs of cooperating hosts.
  58. Reference [4] (section 4.2) should be consulted for further valuable
  59. directives and suggestions on TFTP.
  60. 2. Overview of the Protocol
  61. Any transfer begins with a request to read or write a file, which
  62. also serves to request a connection. If the server grants the
  63. request, the connection is opened and the file is sent in fixed
  64. length blocks of 512 bytes. Each data packet contains one block of
  65. data, and must be acknowledged by an acknowledgment packet before the
  66. next packet can be sent. A data packet of less than 512 bytes
  67. signals termination of a transfer. If a packet gets lost in the
  68. network, the intended recipient will timeout and may retransmit his
  69. last packet (which may be data or an acknowledgment), thus causing
  70. the sender of the lost packet to retransmit that lost packet. The
  71. sender has to keep just one packet on hand for retransmission, since
  72. the lock step acknowledgment guarantees that all older packets have
  73. been received. Notice that both machines involved in a transfer are
  74. considered senders and receivers. One sends data and receives
  75. acknowledgments, the other sends acknowledgments and receives data.
  76. Most errors cause termination of the connection. An error is
  77. signalled by sending an error packet. This packet is not
  78. acknowledged, and not retransmitted (i.e., a TFTP server or user may
  79. terminate after sending an error message), so the other end of the
  80. connection may not get it. Therefore timeouts are used to detect
  81. such a termination when the error packet has been lost. Errors are
  82. Sollins [Page 2]
  83. RFC 1350 TFTP Revision 2 July 1992
  84. caused by three types of events: not being able to satisfy the
  85. request (e.g., file not found, access violation, or no such user),
  86. receiving a packet which cannot be explained by a delay or
  87. duplication in the network (e.g., an incorrectly formed packet), and
  88. losing access to a necessary resource (e.g., disk full or access
  89. denied during a transfer).
  90. TFTP recognizes only one error condition that does not cause
  91. termination, the source port of a received packet being incorrect.
  92. In this case, an error packet is sent to the originating host.
  93. This protocol is very restrictive, in order to simplify
  94. implementation. For example, the fixed length blocks make allocation
  95. straight forward, and the lock step acknowledgement provides flow
  96. control and eliminates the need to reorder incoming data packets.
  97. 3. Relation to other Protocols
  98. As mentioned TFTP is designed to be implemented on top of the
  99. Datagram protocol (UDP). Since Datagram is implemented on the
  100. Internet protocol, packets will have an Internet header, a Datagram
  101. header, and a TFTP header. Additionally, the packets may have a
  102. header (LNI, ARPA header, etc.) to allow them through the local
  103. transport medium. As shown in Figure 3-1, the order of the contents
  104. of a packet will be: local medium header, if used, Internet header,
  105. Datagram header, TFTP header, followed by the remainder of the TFTP
  106. packet. (This may or may not be data depending on the type of packet
  107. as specified in the TFTP header.) TFTP does not specify any of the
  108. values in the Internet header. On the other hand, the source and
  109. destination port fields of the Datagram header (its format is given
  110. in the appendix) are used by TFTP and the length field reflects the
  111. size of the TFTP packet. The transfer identifiers (TID's) used by
  112. TFTP are passed to the Datagram layer to be used as ports; therefore
  113. they must be between 0 and 65,535. The initialization of TID's is
  114. discussed in the section on initial connection protocol.
  115. The TFTP header consists of a 2 byte opcode field which indicates
  116. the packet's type (e.g., DATA, ERROR, etc.) These opcodes and the
  117. formats of the various types of packets are discussed further in the
  118. section on TFTP packets.
  119. Sollins [Page 3]
  120. RFC 1350 TFTP Revision 2 July 1992
  121. ---------------------------------------------------
  122. | Local Medium | Internet | Datagram | TFTP |
  123. ---------------------------------------------------
  124. Figure 3-1: Order of Headers
  125. 4. Initial Connection Protocol
  126. A transfer is established by sending a request (WRQ to write onto a
  127. foreign file system, or RRQ to read from it), and receiving a
  128. positive reply, an acknowledgment packet for write, or the first data
  129. packet for read. In general an acknowledgment packet will contain
  130. the block number of the data packet being acknowledged. Each data
  131. packet has associated with it a block number; block numbers are
  132. consecutive and begin with one. Since the positive response to a
  133. write request is an acknowledgment packet, in this special case the
  134. block number will be zero. (Normally, since an acknowledgment packet
  135. is acknowledging a data packet, the acknowledgment packet will
  136. contain the block number of the data packet being acknowledged.) If
  137. the reply is an error packet, then the request has been denied.
  138. In order to create a connection, each end of the connection chooses a
  139. TID for itself, to be used for the duration of that connection. The
  140. TID's chosen for a connection should be randomly chosen, so that the
  141. probability that the same number is chosen twice in immediate
  142. succession is very low. Every packet has associated with it the two
  143. TID's of the ends of the connection, the source TID and the
  144. destination TID. These TID's are handed to the supporting UDP (or
  145. other datagram protocol) as the source and destination ports. A
  146. requesting host chooses its source TID as described above, and sends
  147. its initial request to the known TID 69 decimal (105 octal) on the
  148. serving host. The response to the request, under normal operation,
  149. uses a TID chosen by the server as its source TID and the TID chosen
  150. for the previous message by the requestor as its destination TID.
  151. The two chosen TID's are then used for the remainder of the transfer.
  152. As an example, the following shows the steps used to establish a
  153. connection to write a file. Note that WRQ, ACK, and DATA are the
  154. names of the write request, acknowledgment, and data types of packets
  155. respectively. The appendix contains a similar example for reading a
  156. file.
  157. Sollins [Page 4]
  158. RFC 1350 TFTP Revision 2 July 1992
  159. 1. Host A sends a "WRQ" to host B with source= A's TID,
  160. destination= 69.
  161. 2. Host B sends a "ACK" (with block number= 0) to host A with
  162. source= B's TID, destination= A's TID.
  163. At this point the connection has been established and the first data
  164. packet can be sent by Host A with a sequence number of 1. In the
  165. next step, and in all succeeding steps, the hosts should make sure
  166. that the source TID matches the value that was agreed on in steps 1
  167. and 2. If a source TID does not match, the packet should be
  168. discarded as erroneously sent from somewhere else. An error packet
  169. should be sent to the source of the incorrect packet, while not
  170. disturbing the transfer. This can be done only if the TFTP in fact
  171. receives a packet with an incorrect TID. If the supporting protocols
  172. do not allow it, this particular error condition will not arise.
  173. The following example demonstrates a correct operation of the
  174. protocol in which the above situation can occur. Host A sends a
  175. request to host B. Somewhere in the network, the request packet is
  176. duplicated, and as a result two acknowledgments are returned to host
  177. A, with different TID's chosen on host B in response to the two
  178. requests. When the first response arrives, host A continues the
  179. connection. When the second response to the request arrives, it
  180. should be rejected, but there is no reason to terminate the first
  181. connection. Therefore, if different TID's are chosen for the two
  182. connections on host B and host A checks the source TID's of the
  183. messages it receives, the first connection can be maintained while
  184. the second is rejected by returning an error packet.
  185. 5. TFTP Packets
  186. TFTP supports five types of packets, all of which have been mentioned
  187. above:
  188. opcode operation
  189. 1 Read request (RRQ)
  190. 2 Write request (WRQ)
  191. 3 Data (DATA)
  192. 4 Acknowledgment (ACK)
  193. 5 Error (ERROR)
  194. The TFTP header of a packet contains the opcode associated with
  195. that packet.
  196. Sollins [Page 5]
  197. RFC 1350 TFTP Revision 2 July 1992
  198. 2 bytes string 1 byte string 1 byte
  199. ------------------------------------------------
  200. | Opcode | Filename | 0 | Mode | 0 |
  201. ------------------------------------------------
  202. Figure 5-1: RRQ/WRQ packet
  203. RRQ and WRQ packets (opcodes 1 and 2 respectively) have the format
  204. shown in Figure 5-1. The file name is a sequence of bytes in
  205. netascii terminated by a zero byte. The mode field contains the
  206. string "netascii", "octet", or "mail" (or any combination of upper
  207. and lower case, such as "NETASCII", NetAscii", etc.) in netascii
  208. indicating the three modes defined in the protocol. A host which
  209. receives netascii mode data must translate the data to its own
  210. format. Octet mode is used to transfer a file that is in the 8-bit
  211. format of the machine from which the file is being transferred. It
  212. is assumed that each type of machine has a single 8-bit format that
  213. is more common, and that that format is chosen. For example, on a
  214. DEC-20, a 36 bit machine, this is four 8-bit bytes to a word with
  215. four bits of breakage. If a host receives a octet file and then
  216. returns it, the returned file must be identical to the original.
  217. Mail mode uses the name of a mail recipient in place of a file and
  218. must begin with a WRQ. Otherwise it is identical to netascii mode.
  219. The mail recipient string should be of the form "username" or
  220. "username@hostname". If the second form is used, it allows the
  221. option of mail forwarding by a relay computer.
  222. The discussion above assumes that both the sender and recipient are
  223. operating in the same mode, but there is no reason that this has to
  224. be the case. For example, one might build a storage server. There
  225. is no reason that such a machine needs to translate netascii into its
  226. own form of text. Rather, the sender might send files in netascii,
  227. but the storage server might simply store them without translation in
  228. 8-bit format. Another such situation is a problem that currently
  229. exists on DEC-20 systems. Neither netascii nor octet accesses all
  230. the bits in a word. One might create a special mode for such a
  231. machine which read all the bits in a word, but in which the receiver
  232. stored the information in 8-bit format. When such a file is
  233. retrieved from the storage site, it must be restored to its original
  234. form to be useful, so the reverse mode must also be implemented. The
  235. user site will have to remember some information to achieve this. In
  236. both of these examples, the request packets would specify octet mode
  237. to the foreign host, but the local host would be in some other mode.
  238. No such machine or application specific modes have been specified in
  239. TFTP, but one would be compatible with this specification.
  240. It is also possible to define other modes for cooperating pairs of
  241. Sollins [Page 6]
  242. RFC 1350 TFTP Revision 2 July 1992
  243. hosts, although this must be done with care. There is no requirement
  244. that any other hosts implement these. There is no central authority
  245. that will define these modes or assign them names.
  246. 2 bytes 2 bytes n bytes
  247. ----------------------------------
  248. | Opcode | Block # | Data |
  249. ----------------------------------
  250. Figure 5-2: DATA packet
  251. Data is actually transferred in DATA packets depicted in Figure 5-2.
  252. DATA packets (opcode = 3) have a block number and data field. The
  253. block numbers on data packets begin with one and increase by one for
  254. each new block of data. This restriction allows the program to use a
  255. single number to discriminate between new packets and duplicates.
  256. The data field is from zero to 512 bytes long. If it is 512 bytes
  257. long, the block is not the last block of data; if it is from zero to
  258. 511 bytes long, it signals the end of the transfer. (See the section
  259. on Normal Termination for details.)
  260. All packets other than duplicate ACK's and those used for
  261. termination are acknowledged unless a timeout occurs [4]. Sending a
  262. DATA packet is an acknowledgment for the first ACK packet of the
  263. previous DATA packet. The WRQ and DATA packets are acknowledged by
  264. ACK or ERROR packets, while RRQ
  265. 2 bytes 2 bytes
  266. ---------------------
  267. | Opcode | Block # |
  268. ---------------------
  269. Figure 5-3: ACK packet
  270. and ACK packets are acknowledged by DATA or ERROR packets. Figure
  271. 5-3 depicts an ACK packet; the opcode is 4. The block number in
  272. an ACK echoes the block number of the DATA packet being
  273. acknowledged. A WRQ is acknowledged with an ACK packet having a
  274. block number of zero.
  275. Sollins [Page 7]
  276. RFC 1350 TFTP Revision 2 July 1992
  277. 2 bytes 2 bytes string 1 byte
  278. -----------------------------------------
  279. | Opcode | ErrorCode | ErrMsg | 0 |
  280. -----------------------------------------
  281. Figure 5-4: ERROR packet
  282. An ERROR packet (opcode 5) takes the form depicted in Figure 5-4. An
  283. ERROR packet can be the acknowledgment of any other type of packet.
  284. The error code is an integer indicating the nature of the error. A
  285. table of values and meanings is given in the appendix. (Note that
  286. several error codes have been added to this version of this
  287. document.) The error message is intended for human consumption, and
  288. should be in netascii. Like all other strings, it is terminated with
  289. a zero byte.
  290. 6. Normal Termination
  291. The end of a transfer is marked by a DATA packet that contains
  292. between 0 and 511 bytes of data (i.e., Datagram length < 516). This
  293. packet is acknowledged by an ACK packet like all other DATA packets.
  294. The host acknowledging the final DATA packet may terminate its side
  295. of the connection on sending the final ACK. On the other hand,
  296. dallying is encouraged. This means that the host sending the final
  297. ACK will wait for a while before terminating in order to retransmit
  298. the final ACK if it has been lost. The acknowledger will know that
  299. the ACK has been lost if it receives the final DATA packet again.
  300. The host sending the last DATA must retransmit it until the packet is
  301. acknowledged or the sending host times out. If the response is an
  302. ACK, the transmission was completed successfully. If the sender of
  303. the data times out and is not prepared to retransmit any more, the
  304. transfer may still have been completed successfully, after which the
  305. acknowledger or network may have experienced a problem. It is also
  306. possible in this case that the transfer was unsuccessful. In any
  307. case, the connection has been closed.
  308. 7. Premature Termination
  309. If a request can not be granted, or some error occurs during the
  310. transfer, then an ERROR packet (opcode 5) is sent. This is only a
  311. courtesy since it will not be retransmitted or acknowledged, so it
  312. may never be received. Timeouts must also be used to detect errors.
  313. Sollins [Page 8]
  314. RFC 1350 TFTP Revision 2 July 1992
  315. I. Appendix
  316. Order of Headers
  317. 2 bytes
  318. ----------------------------------------------------------
  319. | Local Medium | Internet | Datagram | TFTP Opcode |
  320. ----------------------------------------------------------
  321. TFTP Formats
  322. Type Op # Format without header
  323. 2 bytes string 1 byte string 1 byte
  324. -----------------------------------------------
  325. RRQ/ | 01/02 | Filename | 0 | Mode | 0 |
  326. WRQ -----------------------------------------------
  327. 2 bytes 2 bytes n bytes
  328. ---------------------------------
  329. DATA | 03 | Block # | Data |
  330. ---------------------------------
  331. 2 bytes 2 bytes
  332. -------------------
  333. ACK | 04 | Block # |
  334. --------------------
  335. 2 bytes 2 bytes string 1 byte
  336. ----------------------------------------
  337. ERROR | 05 | ErrorCode | ErrMsg | 0 |
  338. ----------------------------------------
  339. Initial Connection Protocol for reading a file
  340. 1. Host A sends a "RRQ" to host B with source= A's TID,
  341. destination= 69.
  342. 2. Host B sends a "DATA" (with block number= 1) to host A with
  343. source= B's TID, destination= A's TID.
  344. Sollins [Page 9]
  345. RFC 1350 TFTP Revision 2 July 1992
  346. Error Codes
  347. Value Meaning
  348. 0 Not defined, see error message (if any).
  349. 1 File not found.
  350. 2 Access violation.
  351. 3 Disk full or allocation exceeded.
  352. 4 Illegal TFTP operation.
  353. 5 Unknown transfer ID.
  354. 6 File already exists.
  355. 7 No such user.
  356. Internet User Datagram Header [2]
  357. (This has been included only for convenience. TFTP need not be
  358. implemented on top of the Internet User Datagram Protocol.)
  359. Format
  360. 0 1 2 3
  361. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  362. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  363. | Source Port | Destination Port |
  364. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  365. | Length | Checksum |
  366. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  367. Values of Fields
  368. Source Port Picked by originator of packet.
  369. Dest. Port Picked by destination machine (69 for RRQ or WRQ).
  370. Length Number of bytes in UDP packet, including UDP header.
  371. Checksum Reference 2 describes rules for computing checksum.
  372. (The implementor of this should be sure that the
  373. correct algorithm is used here.)
  374. Field contains zero if unused.
  375. Note: TFTP passes transfer identifiers (TID's) to the Internet User
  376. Datagram protocol to be used as the source and destination ports.
  377. Sollins [Page 10]
  378. RFC 1350 TFTP Revision 2 July 1992
  379. References
  380. [1] USA Standard Code for Information Interchange, USASI X3.4-1968.
  381. [2] Postel, J., "User Datagram Protocol," RFC 768, USC/Information
  382. Sciences Institute, 28 August 1980.
  383. [3] Postel, J., "Telnet Protocol Specification," RFC 764,
  384. USC/Information Sciences Institute, June, 1980.
  385. [4] Braden, R., Editor, "Requirements for Internet Hosts --
  386. Application and Support", RFC 1123, USC/Information Sciences
  387. Institute, October 1989.
  388. Security Considerations
  389. Since TFTP includes no login or access control mechanisms, care must
  390. be taken in the rights granted to a TFTP server process so as not to
  391. violate the security of the server hosts file system. TFTP is often
  392. installed with controls such that only files that have public read
  393. access are available via TFTP and writing files via TFTP is
  394. disallowed.
  395. Author's Address
  396. Karen R. Sollins
  397. Massachusetts Institute of Technology
  398. Laboratory for Computer Science
  399. 545 Technology Square
  400. Cambridge, MA 02139-1986
  401. Phone: (617) 253-6006
  402. EMail: [email protected]
  403. Sollins [Page 11]