RFC 542

File Transfer Protocol

๐Ÿ“… published August 1973, from ietf

Part 1 of 8, more coming bestie ๐ŸŽ€

File Transfer Protocol for the ARPA Network ๐Ÿฆ‹

okay so this is RFC 542, the File Transfer Protocol ๐Ÿ’–, written by Nancy J. Neigus at Bolt Beranek and Newman, Inc. in Cambridge, Mass. ๐Ÿงš It's dated Aug. 12, 1973 and it's also filed as NIC 17759. The header points to RFCs 354, 454, 495 as "See Also" reads. It doesn't name a category, and it doesn't formally say it obsoletes or updates anything, but the preface does talk about replacing the older 354/385 version of FTP, so keep that in mind ๐Ÿ‘€


PREFACE โœจ

this doc is the result of several months of discussion over RFC ๐Ÿ—ฃ๏ธ (the relevant numbers are 430, 448, 454, 463, 468, 478, 480), then a meeting of the FTP committee at BBN on March 16, then more back and forth between committee members ๐Ÿ’ฌ there are a LOT of changes from the last "official" version (see RFCs 354, 385), but the gross structure is still the same ๐Ÿ™ˆ

the places to look for differences are:

  1. the definitions of types and modes ๐ŸŽ€
  2. the specification of the data connection and data sockets ๐Ÿ”Œ
  3. the command-reply sequences ๐Ÿ“จ
  4. the functions that depend on the TELNET protocol (FTP was changed to match the new TELNET spec) ๐ŸŒˆ

the model was clarified and enlarged so inter-server file transfer is allowed โœจ and several new commands were added for more specialized (or site-specific) functions ๐Ÿ’… the author believes this new spec reflects what the committee said at that March 16 meeting and in later conversations ๐Ÿซถ

the big pile of incompatibilities would make a phased rollout really messy ๐Ÿ˜ญ (the way TELNET did it) so the plan is this:

  • a new socket, decimal 21, is assigned as a temporary logger socket for the new version ๐Ÿฆ‹
  • the change-over date is 1 February 1974 ๐Ÿ“…
  • until that date the old (354, 385) version of FTP stays on Socket 3, and the new version (attached) should be implemented on Socket 21 ๐Ÿ”„
  • on 1 February the new version moves to Socket 3 and the old one disappears ๐Ÿ‘‹

the File Transfer Protocol should be considered stable at least until February ๐Ÿ”’ but you're totally free to propose more changes via RFC ๐Ÿ’œ (trying out new commands on an experimental basis is encouraged too, and that should also be reported by RFC ๐Ÿงช). members of the FTP committee can also be contacted directly about changes. based on who showed up at the March 16 meeting, they are:

Abhay Bhushan MIT-DMCG
Bob Braden UCLA-CCN
Bob Bressler BBN-NET
Bob Clements BBN-TENEX
John Day ILL-ANTS
Peter Deutsch PARC-MAXC
Wayne Hathaway AMES-67
Mike Kudlick SRI-ARC
Alex McKenzie BBN-NET
Bob Merryman UCSD-CC
Nancy Neigus BBN-NET
Mike Padlipsky MIT-Multics
Jim Pepin USC-44
Ken Pogran MIT-Multics
Jon Postel UCLA-NMC
Milton Reese FNWC
Brad Reussow HARV-10
Marc Seriff MIT-DMCG
Ed Taft HARV-10
Bob Thomas BBN-TENEX
Ric Werme CMU-10
Jim White SRI-ARC

I would especially like to thank Bob Braden, Ken Pogran, Wayne Hathaway, Jon Postel, Ed Taft and Alex McKenzie for their help in preparing this document ๐Ÿฅน๐Ÿซถ


INTRODUCTION ๐Ÿ’–

the File Transfer Protocol (FTP) is a protocol for moving files between Hosts (including Terminal Interface Message Processors (TIPs)) on the ARPA Computer Network (ARPANET) ๐ŸŒ its main job is to transfer files efficiently and reliably between Hosts and to let you conveniently use remote file storage ๐Ÿ—‚๏ธโœจ

the objectives of FTP are:

  1. promoting sharing of files (computer programs and/or data) ๐ŸŽ
  2. encouraging indirect or implicit use of remote computers (via programs) ๐Ÿค–
  3. shielding a user from the differences in file storage systems among Hosts ๐Ÿ›ก๏ธ
  4. transferring data reliably and efficiently ๐Ÿ’ช

FTP can be used directly by a user at a terminal, but it's designed mainly for use by programs ๐Ÿงš

this spec is trying to meet the different needs of maxi-Hosts, mini-Hosts, TIPs, and the Datacomputer ๐Ÿ–ฅ๏ธ while keeping the protocol design simple and easy to implement ๐ŸŽ€

this paper assumes you already know these protocols, which are described in NIC #7104:

  • The Host-Host Protocol ๐Ÿ”Œ
  • The Initial Connection Protocol ๐Ÿ“ž
  • The TELNET Protocol โŒจ๏ธ

DISCUSSION โœจ

okay so this section is where we get into the terminology and the FTP model ๐Ÿง  it only covers the terms that have special meaning in FTP, so no need to panic about every word

TERMINOLOGY ๐Ÿ’…

ASCII ๐Ÿ”ค the USASCII character set as defined in NIC #7104. in FTP, ASCII characters are defined to be the lower half of an eight-bit code set (aka the most significant bit is zero) ๐Ÿซถ

access controls ๐Ÿ” access controls define users' access privileges to the use of a system and to the files in that system. they're necessary to prevent unauthorized or accidental use of files. it is the prerogative of a server-FTP process to provide access controls ๐Ÿ‘‘

byte size ๐Ÿ“ the byte size specified for the transfer of data. the data connection is opened with this byte size. the data connection byte size is not necessarily the byte size in which data is to be stored in a system, nor the logical byte size for interpretation of the structure of the data ๐ŸŒธ

data connection ๐ŸŒˆ a simplex connection over which data is transferred, in a specified byte size, mode and type. the data transferred may be a part of a file, an entire file or a number of files. the path may be between a server-DTP and a user-DTP, or between two server-DTPs ๐Ÿฆ‹

data socket ๐Ÿงš the passive data transfer process "listens" on the data socket for an RFC from the active transfer process (server) in order to open the data connection. the server has fixed data sockets; the passive process may or may not ๐Ÿ“

EOF ๐Ÿ the end-of-file condition that defines the end of a file being transferred ๐Ÿ’œ

EOR ๐Ÿ the end-of-record condition that defines the end of a record being transferred ๐Ÿ’œ

error recovery ๐Ÿ›Ÿ a procedure that allows a user to recover from certain errors such as failure of either Host system or transfer process. in FTP, error recovery may involve restarting a file transfer at a given checkpoint ๐Ÿ˜ญ

FTP commands ๐Ÿ“จ a set of commands that comprise the control information flowing from the user-FTP to the server-FTP process ๐Ÿ’–

file ๐Ÿ“ an ordered set of computer data (including programs), of arbitrary length, uniquely identified by a pathname ๐ŸŽ€

mode ๐ŸŽถ the mode in which data is to be transferred via the data connection. the mode defines the data format during transfer, including EOR and EOF. the transfer modes defined in FTP are described in the Section on Transmission Modes ๐Ÿ”ฅ

NVT ๐Ÿ–ฅ๏ธ the Network Virtual Terminal as defined in the ARPANET TELNET Protocol โœจ

NVFS ๐Ÿ—‚๏ธ the Network Virtual File System. it's a concept that defines a standard network file system with standard commands and pathname conventions. FTP only partially embraces the NVFS concept at this time ๐Ÿ™ˆ

pathname ๐Ÿ›ค๏ธ pathname is defined to be the character string which must be input to a file system by a user in order to identify a file. pathnames normally contain device and/or directory names, and a file name specification. FTP does not yet specify a standard pathname convention, so each user must follow the file naming conventions of the file systems they wish to use ๐Ÿซ 

record ๐Ÿงพ a sequential file may be structured as a number of contiguous parts called records. record structures are supported by FTP, but a file need not have record structure ๐Ÿ’…

reply ๐Ÿ’ฌ a reply is an acknowledgment (positive or negative) sent from server to user via the TELNET connections in response to FTP commands. the general form of a reply is a completion code (including error codes) followed by a text string. the codes are for use by programs, and the text is usually intended for human users ๐ŸŒท

server-DTP ๐Ÿšš the data transfer process, in its normal "active" state, establishes the data connection by RFC to the "listening" data socket, sets up parameters for transfer and storage, and tranfers data on command from its PI. the DTP can be placed in a "passive" state to listen for, rather than initiate, an RFC on the data socket ๐Ÿฆข

server-FTP process ๐Ÿ  a process or set of processes which perform the function of file transfer in cooperation with a user-FTP process and, possibly, another server. the functions consist of a protocol interpreter (PI) and a data transfer process (DTP) ๐Ÿงฉ

server-PI ๐ŸŽง the protocol interpreter "listens" on Socket 3 for an ICP from a user-PI and establishes a TELNET communication connection. it receives standard FTP commands from the user-PI, sends replies, and governs the server-DTP ๐Ÿซถ

TELNET connections ๐Ÿ”Œ the full-duplex communication path between a user-PI and a server-PI. the TELNET connections are established via the standard ARPANET Initial Connection Protocol (ICP) โญ

type ๐ŸŽจ the data representation type used for data transfer and storage. type implies certain transformations between the time of data storage and data transfer. the representation types defined in FTP are described in the Section on Establishing Data Connections ๐ŸŒˆ

user ๐Ÿ™‹โ€โ™€๏ธ a human being or a process on behalf of a human being wishing to obtain file transfer service. the human user may interact directly with a server-FTP process, but use of a user-FTP process is preferred since the protocol design is weighted towards automata ๐Ÿค–

user-DTP ๐Ÿ“ก the data transfer process "listens" on the data socket for an RFC from a server-FTP process. if two servers are transferring data between them, the user-DTP is inactive ๐Ÿ’ค

user-FTP process ๐Ÿ’ป a set of functions including a protocol interpreter, a data transfer process and a user interface which together perform the function of file transfer in cooperation with one or more server-FTP processes. the user interface allows a local language to be used in the command-reply dialogue with the user ๐ŸŒ

user-PI ๐Ÿง‘โ€๐Ÿ’ป the protocol interpreter initiates the ICP to the server-FTP process, initiates FTP commands, and governs the user-DTP if that process is part of the file transfer ๐Ÿฆ‹


THE FTP MODEL ๐Ÿงš

okay now the fun part, the model! ๐ŸŽ€ with all those definitions in mind, the following model (shown in Figure 1) can be diagrammed for an FTP service ๐Ÿ“Š

                                     -------------
                                     !/---------\!
                                     !!   User  !!    --------
                                     !!Interface!<--->! User !
                                     !\----:----/!    --------
           ----------                !     V     !
           !/------\!  FTP Commands  !/---------\!
           !!Server!<-----------------!   User  !!
           !!  PI  !----------------->!    PI   !!
           !\--:---/!   FTP Replies  !\----:----/!
           !   V    !                !     V     !
--------   !/------\!      Data      !/---------\!    --------
! File !<--->!Server!<---------------->!  User   !<--->! File !
!System!    !! DTP  !!   Connections  !!   DTP   !!    !System!
--------    !\------/!                !\---------/!    --------
           ----------                -------------

           Server-FTP                   User-FTP

NOTES: 1. The data connection may be in either direction.
       2. The data connection need not exist all of the time.

                 Figure 1  Model for FTP Use

in the model from Figure 1, the user-protocol interpreter initiates the TELNET connections ๐Ÿ”Œ at the user's request, standard FTP commands get generated by the user-PI and sent to the server process over the TELNET connections. (the user can also set up a direct TELNET connection to the server-FTP, from a TIP terminal for example, and generate standard FTP commands themselves, bypassing the user-FTP process ๐Ÿ™Œ) standard replies get sent from the server-PI back to the user-PI over the TELNET connections in response to the commands ๐Ÿ’Œ

the FTP commands specify the parameters for the data connection (data socket, byte size, transfer mode, representation type, and structure) and the nature of the file system operation (store, retrieve, append, delete, etc.) ๐Ÿ—ƒ๏ธ the user-DTP or its designate should "listen" on the specified data socket, and the server initiates the data connection and data transfer in accordance with the specified parameters. it should be noted that the data socket need not be in the same Host that initiates the FTP commands via the TELNET connections, but the user or their user-FTP process must ensure a "listen" on the specified data socket ๐Ÿ‘€ it should also be noted that two data connections, one for send and the other for receive, may exist simultaneously ๐Ÿซจ

in another situation, a user might wish to transfer files between two Hosts, neither of which is their local Host ๐ŸŒ they set up TELNET connections to the two servers and then arrange for a data connection between them. this way control information is passed to the user-PI, but data is transferred between the server data transfer processes. here's a model of this server-server interaction ๐Ÿค

             TELNET     ------------    TELNET
             -----------! User-FTP !------------
             ! -------->! User-PI  !<--------- !
             ! !        !   "C"    !         ! !
             V !        ------------         ! V
     --------------                        --------------
     ! Server-FTP !   Data Connection      ! Server-FTP !
     !    "A"     !<-----------------------!    "B"     !
     -------------- Socket(A)    Socket(B) --------------



                         Figure 2

the protocol requires that the TELNET connections be open while data transfer is in progress ๐Ÿ”’ it's the user's job to request closing the TELNET connections when they're done using the FTP service, while the server is the one who actually takes that action ๐Ÿซก the server may abort data transfer if the TELNET connections are closed without command ๐Ÿšซ


DATA TRANSFER FUNCTIONS ๐ŸŽ€

okay so files only ever move over the data connection(s) ๐Ÿ“ฆ the TELNET connection is used to carry the commands that describe what needs to happen, plus the replies to those commands (see the Section on FTP Replies) ๐Ÿ’ฌ a few commands deal with moving data between Hosts. these include the BYTE, MODE, and SOCKet commands, which specify how the bits of the data are to be transmitted, and the STRUcture and TYPE commands, which define how the data is represented ๐Ÿง  the transmission and representation are basically independent, BUT "Stream" transmission mode depends on the file structure attribute, and if "Compressed" transmission mode is used, the nature of the filler byte depends on the representation type ๐Ÿคฏ it's giving complicated, but it makes sense once you see it all together โœจ

DATA REPRESENTATION AND STORAGE ๐Ÿฆ‹

Okay so data gets moved from a storage device in the sending Host to a storage device in the receiving Host ๐Ÿ’พ๐Ÿš€, and honestly that's where the drama starts, bestie. The two systems often store data in totally different ways, so you usually have to transform it. NVT-ASCII is a perfect example ๐Ÿ™ˆ PDP-10s generally store NVT-ASCII as five 7-bit ASCII characters, left-justified in a 36-bit word. 360s store it as 8-bit EBCDIC codes. Multics stores it as four 9-bit characters in a 36-bit word. It's giving "everyone's storage is different" ๐Ÿ˜ญ So when you send text between dissimilar systems, it can be smart to convert the characters into the standard NVT-ASCII representation. Then the sending and receiving sites each do the necessary transformations between that standard form and their own internal representations ๐Ÿ’…

A different representation problem shows up when you send binary data (not character codes) between Hosts with different word lengths ๐Ÿงฎ It's not always clear how the sender should send it or how the receiver should store it. For example, if you move 32-bit bytes from a 32-bit word-length system to a 36-bit word-length system, it may be desirable (for reasons of efficiency and usefulness) to store those 32-bit bytes right-justified in a 36-bit word on the latter system. Either way, the user should get to choose the data representation and transformation functions ๐ŸŽ€ Heads up, though: FTP only has very limited data type representations โš ๏ธ Transformations you want beyond that should be performed by the user directly, or through the Data Reconfiguration Service (DRS, RFC #138, NIC #6715). Additional representation types may be defined later if there is a demonstrable need.

Data representations are handled in FTP when a user specifies a representation type ๐Ÿฆ‹ This type may implicitly (as in ASCII or EBCDIC) or explicitly (as in Local byte) define a byte size for interpretation, which is referred to as the "logical byte size." This has nothing to do with the byte size used for transmission over the data connection(s) (called the "transfer byte size"), and the two should not be confused. For example, NVT-ASCII has a logical byte size of 8 bits, but an ASCII file might be transferred using a transfer byte size of 32. If the type is Local byte, then the TYPE command has an obligatory second parameter specifying the logical byte size.

The types ASCII and EBCDIC also take a second (optional) parameter. This indicates what kind of vertical format control, if any, is associated with a file. The following data representation types are defined in FTP:

ASCII Format ๐Ÿ”ค

This is the default type and must be accepted by all FTP implementations. It's intended mainly for transferring text files, except when both Hosts would find the EBCDIC type more convenient โœจ

The sender converts the data from its internal character representation to the standard 8-bit NVT-ASCII representation (see the TELNET specification). The receiver converts the data from the standard form to its own internal form.

In accordance with the NVT standard, the <CRLF> sequence should be used, where necessary, to denote the end of a line of text. (See the discussion of file structure at the end of the Section on Data Representation and Storage.)

Using the standard NVT-ASCII representation means that data must be interpreted as 8-bit bytes. If the BYTE command (see the Section on Transfer Parameter Commands) specifies a transfer byte size different from 8 bits, the 8-bit ASCII characters should be packed contiguously without regard for transfer byte boundaries.

The Format parameter for ASCII and EBCDIC types is discussed below. ๐ŸŒธ

EBCDIC Format ๐Ÿงถ

This type is intended for efficient transfer between Hosts that use EBCDIC for their internal character representation ๐Ÿ’œ

For transmission, the data are represented as 8-bit EBCDIC characters. The character code is the only difference between the functional specifications of the EBCDIC and ASCII types.

End-of-line (as opposed to end-of-record, see the discussion of structure) will probably be rarely used with the EBCDIC type to denote structure, but where it is necessary, the <NL> character should be used.

A character file may be transferred to a Host for one of three purposes: for printing, for storage and later retrieval, or for processing. If a file is sent for printing, the receiving Host must know how the vertical format control is represented. In the second case, it must be possible to store a file at a Host and then retrieve it later in exactly the same form. Finally, it ought to be possible to move a file from one Host to another and process it at the second Host without undue trouble. A single ASCII or EBCDIC format doesn't satisfy all of these conditions, so these types have a second parameter specifying one of the following three formats ๐ŸŽ€

Non-print ๐Ÿ“„

This is the default format used if the second (format) parameter is omitted. Non-print format must be accepted by all FTP implementations.

The file need not contain any vertical format information. If it is passed to a printer process, that process may assume standard values for spacing and margins.

Normally, this format is used with files destined for processing or just storage.

TELNET Format Controls ๐Ÿ–จ๏ธ

The file contains ASCII/EBCDIC vertical format controls (i.e., <CR>, <LF>, <NL>, <VT>, <FF>), which the printer process will interpret appropriately. <CRLF>, in exactly this sequence, also denotes end-of-line.

Carriage Control (ASA) ๐Ÿงพ

The file contains ASA (FORTRAN) vertical format control characters. (See NWG/RFC #189 Appendix C and Communications of the ACM, Vol. 7, No. 10, 606 (Oct. 1964).) In a line or a record formatted according to the ASA Standard, the first character is not to be printed. Instead, it should be used to determine the vertical movement of the paper that should take place before the rest of the record is printed. The ASA Standard specifies the following control characters:

Character     Vertical Spacing

blank         Move paper up one line
0             Move paper up two lines
1             Move paper to top of next page
+             No movement, i.e., overprint

Clearly, there must be some way for a printer process to distinguish the end of the structural entity. If a file has record structure (see below), that's no problem, because records will be explicitly marked during transfer and storage. If the file has no record structure, the <CRLF> end-of-line sequence is used to separate printing lines, but these format effectors are overridden by the ASA controls.

Image ๐Ÿ–ผ๏ธ

The data are sent as contiguous bits which, for transfer, are packed into transfer bytes of the size specified in the BYTE command. The receiving site must store the data as contiguous bits. The structure of the storage system might necessitate padding the file (or each record, for a record-structured file) to some convenient boundary (byte, word or block). This padding, which must be all zeroes, may occur only at the end of the file (or at the end of each record), and there must be a way of identifying the padding bits so that they may be stripped off if the file is retrieved. The padding transformation should be well publicized to enable a user to process a file at the storage site.

Image type is intended for the efficient storage and retrieval of files and for the transfer of binary data. It is recommended that this type be accepted by all FTP implementations ๐Ÿ’–

Local byte Byte size ๐Ÿงฎ

The data is transferred in logical bytes of the size specified by the obligatory second parameter, Byte size. The value of Byte size must be a decimal integer; there is no default value. The logical byte size is not necessarily the same as the transfer byte size. If the byte sizes differ, the logical bytes should be packed contiguously, disregarding transfer byte boundaries, and with any necessary padding at the end.

When the data reaches the receiving Host, it will be transformed in a manner that depends on the logical byte size and the particular Host. This transformation must be invertible (that is, an identical file can be retrieved if the same parameters are used) and should be well publicized by the FTP implementors ๐Ÿ”

This type is intended for the transfer of structured data. For example, a user sending 36-bit floating-point numbers to a Host with a 32-bit word could send their data as Local byte with a logical byte size of 36. The receiving Host would then be expected to store the logical bytes so that they could be easily manipulated. In this example, putting the 36-bit logical bytes into 64-bit double words should suffice โœจ

A note of caution about parameters: a file must be stored and retrieved with the same parameters if the retrieved version is to be identical to the version originally transmitted. Conversely, FTP implementations must return a file identical to the original if the parameters used to store and retrieve a file are the same. ๐Ÿšจ

In addition to different representation types, FTP allows the structure of a file to be specified. Currently two file structures are recognized in FTP: file-structure, where there is no internal structure, and record-structure, where the file is made up of records. File-structure is the default, to be assumed if the STRUcture command has not been used, but both structures must be accepted for "text" files (i.e., files with TYPE ASCII or EBCDIC) by all FTP implementations. The structure of a file will affect both the transfer mode of the file (see the Section on Transmission Modes) and the interpretation and storage of the file ๐ŸŒˆ

The "natural" structure of a file depends on which Host stores it. A source-code file will usually be stored on an IBM 360 in fixed-length records, but on a PDP-10 as a stream of characters partitioned into lines, for example by <CRLF>. If the transfer of files between such disparate sites is to be useful, there must be some way for one site to recognize the other's assumptions about the file ๐Ÿ‘‘

With some sites being naturally file-oriented and others naturally record-oriented, there may be problems if a file with one structure is sent to a Host oriented to the other. If a text file is sent with record-structure to a Host that is file oriented, then that Host should apply an internal transformation to the file based on the

record structure ๐Ÿ’… okay so obviously this transformation should be useful, but it MUST also be invertible so that an identical file may be retrieved using record structure ๐ŸŽ€

now if a file gets sent with file-structure to a record-oriented Host, the Host has to decide how to chop it into records it can process locally ๐Ÿงฉ if it does need to divide things up, the FTP implementation SHOULD use the end-of-line sequence as the delimiter: <CRLF> for ASCII, or <NL> for EBCDIC text files. and if an FTP implementation goes with this technique, it MUST be prepared to reverse the transformation when the file is retrieved with file-structure. no skipping that part bestie ๐Ÿ˜ญ

ESTABLISHING DATA CONNECTIONS โœจ

okay so the mechanics of transferring data are basically two things: setting up the data connection to the right sockets, and choosing the parameters for the transfer, which means byte size and mode ๐Ÿฆ‹ both the user and the server-DTPs have default data sockets. these are the two sockets (for send and receive) sitting right after the standard ICP TELNET socket, so (U+4) and (U+5) for the user-process and (S+2), (S+3) for the server. the default sockets keep the data transfer secure without anyone having to explicitly exchange socket info, which is honestly so clean ๐ŸŒธ

the byte size for the data connection is set by the BYTE command, or it defaults to 8-bit bytes if you leave it unspecified ๐Ÿ’œ this byte size only matters for the actual transfer of the data. it has zero bearing on how the data is represented inside a Host's file system, so don't mix those up ๐Ÿ™ˆ the protocol does not require servers to accept all possible byte sizes. since different byte sizes exist for efficiency of transfer, servers MAY implement only the sizes where their data transfer is efficient, and that includes the default byte size of 8 bits ๐Ÿ“

the passive data transfer process (this may be a user-DTP or a second server-DTP) SHALL "listen" on the data socket before sending a transfer request command ๐Ÿ‘‘ the FTP request command decides the direction of the data transfer, and that decides which data socket (odd or even) gets used to establish the connection. the server, once it gets the transfer request, starts the data connection by RFC to the appropriate socket using the specified (or default) byte size. when the connection opens, the data transfer begins between the DTPs, and the server-PI sends a confirming reply to the user-PI ๐Ÿซถ

it's also possible for the user to specify an alternate data socket with the SOCK command. like, maybe they want a file dumped on a TIP line printer, or retrieved from a third party Host ๐Ÿ–จ๏ธ in that latter case the user-PI sets up TELNET connections with both server-PIs and sends each one a SOCK command indicating the fixed data sockets of the other. then one server gets told (by an FTP command) to "listen" for an RFC which the other will initiate, and finally both get sent the appropriate transfer commands. the exact sequence of commands and replies between the user-controller and the servers is defined in the Section on FTP Replies ๐Ÿงš

in general, maintaining the data connection is the server's job. it's the one that initiates the RFC's and the closes. the exception is when the user-DTP is sending data in a transfer mode that needs the connection closed to signal EOF. the server MUST close the data connection under the following conditions:

  1. The server has completed sending data in a transfer mode that requires a close to indicate EOF.
  2. The server receives an ABORT command from the user.
  3. The socket or byte size specification is changed by a command from the user.
  4. The TELNET connections are closed legally or otherwise.
  5. An irrecoverable error condition occurs.

otherwise, closing is a server option. if the server uses that option, it has to tell the user-process with an appropriate reply ๐Ÿ’€

TRANSMISSION MODES ๐ŸŒˆ

the next thing to think about when transferring data is picking the right transmission mode ๐Ÿ’– there are three modes. one formats the data and allows for restart procedures. one also compresses the data for efficient transfer. and one passes the data through with little or no processing. in that last case the mode interacts with the structure attribute to decide what processing happens. in compressed mode, the representation type decides the filler byte โœจ

all data transfers must finish with an end-of-file (EOF) marker, which can be stated explicitly or implied by closing the data connection. for files with record structure, all the end-of-record markers (EOR) are explicit, including the final one ๐ŸŽ€

Note: In the rest of this section, byte means "transfer byte" except where explicitly stated otherwise.

the following transmission modes are defined in FTP:

Stream ๐ŸŒŠ

the data is sent as a stream of bytes. there's no restriction on the representation type, and record structures are allowed. if you do use record structures, the transfer byte size MUST be at least 3 bits! ๐Ÿ˜ค

in a record structured file, EOR and EOF each get indicated by a two-byte control code, using whatever byte size is being used for the transfer. the first byte of the control code is all ones, the escape character. the second byte has the low order bit on and zeroes everywhere else for EOR, and the second low order bit on for EOF. that means the byte has value 1 for EOR and value 2 for EOF ๐Ÿฆ‹ EOR and EOF can also be indicated together on the last byte transmitted by turning both low order bits on, so the value 3. and if a byte of all ones was meant to be sent as data, it SHOULD be repeated in the second byte of the control code ๐Ÿง 

if the file doesn't have record structure, EOF is indicated by the sending Host closing the data connection, and all bytes are data bytes ๐ŸŒธ

for standardized transfer, the sending Host translates its internal end of line or end of record denotation into the representation prescribed by the transfer mode and file structure. then the receiving Host does the inverse translation back to its own internal denotation ๐Ÿ” an IBM 360 record count field may not be recognized at another Host, so end of record info might get transferred as a two byte control code in Stream mode, or as a flagged bit in a Block or Compressed mode descriptor. end of line in an ASCII or EBCDIC file with no record structure SHOULD be indicated by <CRLF> or <NL>, respectively ๐Ÿ’… these transformations are extra work for some systems, so identical systems transferring non-record structured text files might want to use a binary representation and stream mode instead ๐Ÿซถ

Block ๐Ÿงฑ

the file is sent as a series of data blocks, each one preceded by one or more header bytes. the header bytes hold a count field and a descriptor code. the count field gives the total length of the data block in bytes, which marks where the next data block begins (there are no filler bits, so no padding surprises ๐Ÿ™Œ). the descriptor code defines: last block in the file (EOF), last block in the record (EOR), restart marker (see the Section on Error Recovery and Restart), or suspect data (aka the data being transferred is suspected of errors and isn't reliable) ๐ŸŒง๏ธ this last code is NOT intended for error control within FTP. it's for sites exchanging certain kinds of data, like seismic or weather data, which want to send and receive all the data despite local errors (like "magnetic tape read errors"), but still want to mark certain portions as suspect ๐Ÿ” record structures are allowed in this mode, and any representation type can be used. there's no restriction on the transfer byte size either ๐ŸŽ‰

the header is the smallest integral number of bytes whose length is greater than or equal to 24 bits. only the LEAST significant 24 bits (right-justified) of the header SHALL have information. the remaining most significant bits are "don't care" bits. out of the 24 bits of header information, the 16 low order bits SHALL represent the byte count, and the 8 high order bits SHALL represent descriptor codes, as shown below ๐Ÿงฎ

Integral number of bytes greater than or equal to 24 bits
--------------------------------------------------------
!    Don't care    !    Descriptor    !    Byte Count  !
!  0 to 231 bits   !      8 bits      !     16 bits    !
--------------------------------------------------------

the descriptor codes are indicated by bit flags in the descriptor byte. four codes have been assigned, and each code number is the decimal value of its corresponding bit in the byte ๐Ÿ”ข

   Code     Meaning

    128     End of data block is EOR
     64     End of data block is EOF
     32     Suspected errors in data block
     16     Data block is a restart marker

with this encoding, more than one descriptor coded condition can exist for a particular block. as many bits as necessary may be flagged ๐Ÿง

the restart marker is embedded in the data stream as an integral number of 8-bit bytes representing printable characters in the language being used over the TELNET connection (e.g., default--NVT-ASCII) ๐Ÿ’ฌ these marker bytes are right-justified in the smallest integral number of transfer bytes greater than or equal to 8 bits. for example, if the byte size is 7 bits, the restart marker byte would be one byte right-justified per two 7-bit bytes, like this:

     Two 7-bit bytes
-------------------------
!        !  Marker Char !
!        !     8 bits   !
-------------------------

if the transfer byte size is 16 or more bits, the maximum possible number of complete marker bytes SHOULD be packed, right-justified, into each transfer byte. the restart marker SHOULD begin in the first marker byte. if there are any unused marker bytes, they SHOULD be filled with the character <SP> (Space, in the appropriate language). <SP> MUST NOT be used WITHIN a restart marker ๐Ÿšซ for example, to transmit a six-character marker with a 36-bit transfer byte size, the following three 36-bit bytes would be sent ๐Ÿ‘€

------------------------------------------
! Don't care !Descriptor! Byte count = 2 !
!   12 bits  ! code = 16!                !
------------------------------------------

------------------------------------------
!    ! Marker ! Marker ! Marker ! Marker !
!    ! 8 bits ! 8 bits ! 8 bits ! 8 bits !
------------------------------------------

------------------------------------------
!    ! Marker ! Marker ! Space  ! Space  !
!    ! 8 bits ! 8 bits ! 8 bits ! 8 bits !
------------------------------------------

Compressed ๐Ÿ—œ๏ธ

The file moves across the wire as a series of bytes, sized by the BYTE command ๐Ÿ’Œ There are three kinds of stuff that can get sent: regular data as a byte string, compressed data (replications or filler), and control information, which rides in a two-byte escape sequence ๐ŸŽ€ If the byte size is B bits and you're sending n>0 bytes of regular data, those n bytes get a header byte first. Its left-most bit is 0, and its right-most B-1 bits hold the number n ๐ŸŒธ

                        1  B-1    B        B
                       -------  ------   ------
         Byte string:  !0! n !  !d(1)!...!d(n)!
                       -------  ------   ------
                                ^             ^
                                !---n bytes---!
                                    of data

            String of n data bytes d(1),..., d(n)
            Count n must be positive

To compress a string of n replications of the data byte d, you send 2 bytes ๐Ÿ“

                              2     B-2       B
                           ---------------  ------
         Replicated Byte:  ! 1 0 !   n   !  ! d  !
                           ---------------  ------

A string of n filler bytes can be squished into a single byte, and the filler byte depends on the representation type โœจ For ASCII or EBCDIC, the filler is <SP> (Space, ASCII code 32, EBCDIC code 64). If the transfer byte size is not 8, the expanded byte string should be filled with 8-bit <SP> characters, the same way the ASCII representation type describes it (see the Section on Data Representation and Storage). For Image or Local byte, the filler is a zero byte ๐Ÿ’œ

                            2     B-2
                         ---------------
         Filler String:  ! 1 1 !   n   !
                         ---------------

The escape sequence is a double byte. The first one is the escape byte (all zeroes), and the second one holds the descriptor codes defined in Block mode ๐Ÿฆ‹ This means the byte size has to be at least 8 bits, which isn't much of a restriction for efficiency in this mode. The descriptor codes mean the same thing as they do in Block mode and apply to the string of bytes that comes next ๐Ÿ’…

Compressed mode is useful for getting extra bandwidth on very large network transmissions, for a little extra CPU cost. It works best when the byte size is the word size of the sending Host, and it can really shrink printer files like the ones RJE Hosts generate ๐Ÿ–จ๏ธโœจ

ERROR RECOVERY AND RESTART ๐Ÿ›Ÿ

Okay, so there is no provision for detecting bits that get lost or scrambled during data transfer ๐Ÿ˜ฌ This is probably handled best at the NCP level, where it helps the most users. BUT there is a restart procedure to protect users from gross system failures, including failures of a Host, an FTP-process, or the IMP subnet ๐Ÿซถ

The restart procedure is only defined for the block and compressed modes of data transfer. It requires the sender of the data to insert a special marker code in the data stream, along with some marker information. The marker information only has meaning to the sender, but it must consist of printable characters in the default or negotiated language of the TELNET connection. The marker could represent a bit-count, a record-count, or any other info that lets a system identify a data checkpoint ๐Ÿงš The receiver, if it implements the restart procedure, marks the matching position of this marker in its own system and hands that info back to the user.

If the system fails, the user can restart the data transfer by pointing at the marker with the FTP restart procedure ๐Ÿ’€

Here's how it plays out. The sender inserts a marker block into the data stream at a convenient point. The receiving Host marks the matching data point in its file system and tells the user the last known sender and receiver marker information. It does this either directly or over the TELNET connection in a 251 reply, depending on who the sender was. If the system fails, the user or controller process restarts the server at the last server marker by sending a restart command with the server's marker code as its argument. The restart command goes over the TELNET connection and is immediately followed by the command (such as RETR, STOR or LIST) that was running when the failure happened ๐ŸŒˆ

FILE TRANSFER FUNCTIONS ๐Ÿ“‚

The communication channel from the user-PI to the server-PI is set up by ICP from the user to a standard server socket. The user protocol interpreter is in charge of sending FTP commands and interpreting the replies it gets back. The server-PI interprets commands, sends replies, and directs its DTP to set up the data connection and transfer the data ๐Ÿ‘‘ If the second party to the data transfer (the passive transfer process) is the user-DTP, it's governed through the internal protocol of the user-FTP Host. If it's a second server-DTP, then its PI governs it, on command from the user-PI ๐ŸŒธ

FTP COMMANDS ๐ŸŽ€

The File Transfer Protocol follows the TELNET protocol specs for all communications over the TELNET connection, see NIC #7104. The language used for TELNET communication might become a negotiated option someday, so all references in the next two sections will say "TELNET language" and "TELNET end of line code." For now, you can take those to mean NVT-ASCII and <CRLF>. No other TELNET protocol specs will be cited ๐Ÿ’–

FTP commands are "TELNET strings" ended by the "TELNET end of line code." The command codes are alphabetic characters, ended by a <SP> (Space) if parameters follow, or by TELNET-EOL if they don't. The command codes and what commands mean are described in this section. The detailed syntax is in the Section on Commands, the reply sequences are in the Section on Sequencing of Commands and Replies, and scenarios showing commands in action are in the Section on Typical FTP Scenarios ๐Ÿ“š

FTP commands can be grouped as ones that set access-control identifiers, ones that set data transfer parameters, or ones that make FTP service requests. Certain commands (like ABOR, STAT, BYE) may be sent over the TELNET connections while a data transfer is happening. Some servers can't monitor the TELNET and data connections at the same time, so in that case some special action is needed to get the server's attention ๐Ÿ˜ค The exact form of that "special action" is still being decided by the TELNET committee, but the following ordered format is tentatively recommended:

  1. User system inserts the TELNET "Interrupt Process" (IP) signal in the TELNET stream.
  2. User system sends the TELNET "Synch" signal.
  3. User system inserts the command (e.g., ABOR) in the TELNET stream.
  4. Server PI, after receiving "IP", scans the TELNET stream for EXACTLY ONE FTP command.

For other servers this may not be necessary, but the actions above should have no unusual effect ๐Ÿ™ˆ

ACCESS CONTROL COMMANDS ๐Ÿ”

The following commands specify access control identifiers (command codes are in parentheses).

USER NAME (USER)

The argument field is a TELNET string that identifies the user. The user identification is whatever the server needs for access to its file system. This command will normally be the first one the user sends after the TELNET connections are made (some servers may require this). Some servers also want a password and/or an account command for extra identification. Servers may allow a new USER command at any point to change the access control and/or accounting information. This flushes any user, password, and account info already supplied and starts the login sequence over again. All transfer parameters stay unchanged, and any file transfer in progress finishes under the old account ๐Ÿงพ

PASSWORD (PASS)

The argument field is a TELNET string that identifies the user's password. This command must come right after the user name command, and for some sites it completes the user's identification for access control. Password info is super sensitive, so it's generally desirable to "mask" it or suppress typeout. The server doesn't seem to have any foolproof way to do this, so it's the responsibility of the user-FTP process to hide the sensitive password info ๐Ÿ™ˆ๐Ÿ”’

ACCOUNT (ACCT)

The argument field is a TELNET string that identifies the user's account. This command isn't necessarily related to the USER command, since some sites need an account for login and others only for specific access, like storing files. In that second case, the command can arrive at any time. There are two reply codes so the automaton can tell these cases apart. If account info is required for login, the reply to a successful PASSword command is reply code 331. Then, if a command other than ACCounT is sent, the server may remember it and return a 331 reply, ready to act on the command once the account info arrives. Or it may flush the command and return a 433 reply asking for the account ๐Ÿฆ

On the other hand, if account information is NOT required for login, the reply to a successful PASSword command is 230. If the info is needed for a command sent later in the dialogue, the server should return a 331 or 433 reply, depending on whether it stores the command (pending receipt of the ACCounT command) or discards it, respectively ๐Ÿ’œ

REINITIALIZE (REIN)

This command terminates a USER and flushes all I/O and account information, except to let any transfer in progress finish. All parameters reset to their default settings, and the TELNET connection stays open. This is identical to the state a user is in right after the ICP is completed and the TELNET connections are opened. A USER command may be expected to follow ๐Ÿ”„

LOGOUT (BYE)

This command terminates a USER. If file transfer is not in progress, the server closes the TELNET connection. If file transfer is in progress, the connection stays open for the result response, and the server closes it afterward ๐Ÿ‘‹ If the user-process is transferring files for several USERs but doesn't want to close and then reopen connections for each one, it should use the REIN command instead of BYE ๐Ÿซถ

An unexpected drop on the TELNET connection makes the server take the effective action of an abort (ABOR) and a logout (BYE). No warning, no drama, just automatic cleanup ๐Ÿงนโœจ

TRANSFER PARAMETER COMMANDS ๐ŸŽ€

okay so every data transfer parameter comes with a default value ๐Ÿ’– You only need these commands if you want to change a default. The default is the last value you set, or the standard default if you never set one. That means the server MUST remember the applicable defaults ๐Ÿง  The commands MAY come in any order, except that they MUST come before the FTP service request. Here are the commands that set transfer parameters.

BYTE SIZE (BYTE) ๐Ÿ“

The argument is a decimal integer from 1 through 255 that sets the byte size for the data connection. The default byte size is 8 bits. A server MAY reject byte sizes it hasn't implemented.

DATA SOCKET (SOCK) ๐Ÿฆ‹

The argument is a HOST-SOCKET specification for the data socket used in the data connection. There can be two data sockets. One carries transfer from the "active" DTP to the "passive" DTP, and the other carries transfer from "passive" to "active". An odd socket number defines a send socket, and an even socket number defines a receive socket. The default HOST is the user Host that TELNET connections are made to. The default data sockets are (U+4) and (U+5), where U is the socket number used in the TELNET ICP, and the TELNET connections are on sockets (U+2) and (U+3). The server also has fixed data sockets, (S+2) and (S+3). Under normal circumstances this command and its reply are not needed ๐Ÿ™ˆ

PASSIVE (PASV) ๐Ÿงš

This command asks the server-DTP to "listen" on both of its data sockets and to wait for an RFC to arrive on one socket, instead of starting one as soon as it gets a transfer command. The server is assumed to have already received a SOCK command that names the foreign socket the RFC will arrive from. That's how the transfer stays secure ๐Ÿ”’

REPRESENTATION TYPE (TYPE) ๐Ÿ’œ

The argument sets the representation type, as described in the Section on Data Representation and Storage. Some types take a second parameter. The first parameter is a single TELNET character, and so is the second Format parameter for ASCII and EBCDIC. For local byte, the second parameter is a decimal integer giving the Bytesize. The parameters are separated by a <SP> (Space, ASCII code 32.). These are the codes assigned for type:

                      \    /
            A - ASCII !    ! N - Non-print
                      !-><-! T - TELNET format effectors
            E - EBCDIC!    ! C - Carriage Control (ASA)
                      /    \
            I - Image

            L # - Local byte Bytesize

The default representation type is ASCII Non-print. If the Format parameter gets changed, and later only the first argument changes, Format goes back to the Non-print default ๐ŸŒธ

FILE STRUCTURE (STRU) ๐ŸŒˆ

The argument is a single TELNET character code for the file structure described in the Section on Data Representation and Storage. These are the codes assigned for structure:

  • F - File (no record structure)
  • R - Record structure

The default structure is File (i.e., no records) โญ

TRANSFER MODE (MODE) ๐Ÿ”ฅ

The argument is a single TELNET character code for the data transfer modes described in the Section on Transmission Modes. These are the codes assigned for transfer modes:

  • S - Stream
  • B - Block
  • C - Compressed

The default transfer mode is Stream ๐Ÿ‘‘

FTP SERVICE COMMANDS ๐Ÿ’…

FTP service commands are how the user asks for a file transfer or a file system function. The argument of an FTP service command is normally a pathname. Pathname syntax MUST conform to server site conventions (with standard defaults applicable) and to the language conventions of the TELNET connection. A suggested default is to use the last specified device, directory or file name, or the standard default for local users. The commands MAY come in any order, except that a "rename from" command MUST be followed by a "rename to" command, and the restart command MUST be followed by the interrupted service command. Data sent in response to FTP service commands SHALL always go over the data connection, except for certain informative replies. These are the FTP service requests:

RETRIEVE (RETR) ๐Ÿซถ

This command makes the server-DTP send a copy of the file named in the pathname to the server- or user-DTP at the other end of the data connection. The status and contents of the file at the server site SHALL be unaffected ๐Ÿง

STORE (STOR) ๐Ÿ’–

This command makes the server-DTP accept the data sent over the data connection and store it as a file at the server site. If the file named in the pathname already exists at the server site, its contents SHALL be replaced by the data being transferred. If the file named in the pathname doesn't exist yet, a new file is created at the server site โœจ

APPEND (with create) (APPE) ๐Ÿฆ‹

This command makes the server-DTP accept the data sent over the data connection and store it in a file at the server site. If the file named in the pathname exists at the server site, the data SHALL be appended to that file. Otherwise, the file named in the pathname SHALL be created at the server site ๐ŸŒท

ALLOCATE (ALLO) ๐Ÿง 

Some servers MAY require this command to reserve enough storage for the new file that's coming. The argument SHALL be a decimal integer for the number of bytes (using the logical byte size) to reserve for the file. For files sent with record structure, a maximum record size (in logical bytes) might also be needed. That's given as a decimal integer in a second argument field. The second argument is OPTIONAL, but when it's there, it SHOULD be separated from the first by the three TELNET characters <SP> R <SP>. This command SHALL be followed by a STORe or APPEnd command. Servers that don't need the maximum file size declared beforehand SHOULD treat ALLO as a NOOP (no operation) ๐Ÿ˜ด Servers that only care about the maximum record size SHOULD accept a dummy value in the first argument and ignore it ๐Ÿ™ƒ

RESTART (REST) ๐Ÿ”

The argument field holds the server marker where file transfer should restart. This command doesn't start a transfer. Instead it "spaces" over the file up to the specified data checkpoint. This command SHALL be immediately followed by the matching FTP service command, which SHALL make the file transfer resume ๐ŸŽฌ

RENAME FROM (RNFR) โœ๏ธ

This command names the file to be renamed. It MUST be immediately followed by a "rename to" command that gives the new file pathname ๐Ÿ’Œ

RENAME TO (RNTO) ๐Ÿ“

This command gives the new pathname for the file named in the immediately preceding "rename from" command. Together, the two commands rename the file ๐Ÿ’ซ

ABORT (ABOR) ๐Ÿ›‘

This command tells the server to abort the previous FTP service command and any transfer of data tied to it. The abort command MAY need "special action", as discussed in the Section on FTP Commands, to get the server to recognise it. If the previous command has already completed, including its data transfer, no action is to be taken. The server does not close the TELNET connections, but the data connection MUST be closed. The server SHOULD send an appropriate reply in all cases ๐Ÿšซ

DELETE (DELE) ๐Ÿ—‘๏ธ

This command makes the server delete the file named in the pathname at the server site. If an extra layer of protection is wanted, such as the query "DO you really wish to delete?", it SHOULD be provided by the user-FTP process ๐Ÿ™‹โ€โ™€๏ธ

LIST (LIST) ๐Ÿ“‹

This command makes the server send a list to the passive DTP. If the pathname names a directory, the server SHOULD transfer a list of the files in that directory. If the pathname names a file, the server SHOULD send current information about that file. A null argument means the user's current working or default directory. The data transfer goes over the data connection in type ASCII or type EBCDIC. (The user MUST make sure the TYPE is correctly ASCII or EBCDIC ๐Ÿซ )

NAME-LIST (NLST) ๐Ÿ—‚๏ธ

This command makes the server send a directory listing to the user site. The pathname SHOULD name a directory or another system-specific file group descriptor. A null argument means the current directory. The server returns a stream of file names and nothing else. The data goes over the data connection in ASCII or EBCDIC type, as valid pathname strings separated by <CRLF> or <NL>. (Again, the user MUST make sure the TYPE is right ๐ŸŽฏ)

SITE PARAMETERS (SITE) ๐Ÿ 

The server uses this command to provide services specific to its system. They're essential to file transfer but not universal enough to be commands in the protocol. The nature of these services and the syntax for them can be given in a reply to the HELP SITE command ๐ŸŒŸ

STATUS (STAT) ๐Ÿ“ก

This command SHALL make the server send a status response over the TELNET connection, as a reply. The command MAY be sent during a file transfer, along with the TELNET IP and Synch signals (see the Section on FTP Commands). In that case the server responds with the status of the operation in progress. The command MAY also be sent between file transfers. In that latter case the command MAY have an argument field. If the argument is a pathname, the command works like the "list" command, except that the data SHALL be transferred over the TELNET connection. If a partial pathname is given, the server MAY respond with a list of file names or attributes that match it. If there's no argument, the server SHOULD return general status information about the server FTP process. This SHOULD include the current values of all transfer parameters and the status of connections ๐Ÿ“Š

HELP (HELP) ๐Ÿงšโ€โ™€๏ธ

This command SHALL cause the server to send helpful information about its implementation status over the TELNET connection to the user โœจ You can give it an argument (like any command name) and it MAY return more specific info back ๐Ÿ’… The reply is type Oxx, general system status ๐Ÿ”ฅ It is suggested that HELP be allowed before entering a USER command ๐Ÿซถ The server MAY use this reply to specify site-dependent parameters, e.g., in response to HELP SITE ๐Ÿ“

NOOP (NOOP)

NOOP is the chill command ๐Ÿง˜โ€โ™€๏ธ It doesn't change any parameters or previously entered commands. The only thing it does is make the server send a 200 reply, and that's it ๐Ÿ’–

MISCELLANEOUS COMMANDS

Okay so there are a few functions that use file transfer but go way beyond it in scope ๐ŸŒˆ Those are Mail and Remote Job Entry (RJE). It is suggested that these become auxiliary protocols that can assume the server recognizes file transfer commands, i.e., they MAY depend on the core of FTP commands ๐ŸŽ€ The command sets specific to Mail and RJE will be given in separate documents ๐Ÿ“„

Commands that are closely related to file transfer but not proven essential to the protocol MAY be implemented by servers on an experimental basis ๐Ÿงช The command name SHOULD begin with an X, and it MAY be listed in the HELP command โœจ The official command set is expandable from these experiments, and all experimental commands or proposals for expanding the official command set SHOULD be announced via RFC ๐Ÿ“ฃ An example of a current experimental command is:

Change Working Directory (XCWD)

This one is so useful ๐Ÿ’… It lets the user work with a different directory or dataset for file storage or retrieval without messing with their login or accounting information ๐Ÿซง Transfer parameters stay the same too. The argument is a pathname specifying a directory or other system dependent file group designator ๐Ÿ“

FTP REPLIES

The server sends FTP replies over the TELNET connection in response to user FTP commands ๐Ÿ’Œ These replies are the acknowledgment or completion code (errors included!) ๐Ÿ˜ญ The FTP-server replies are formatted so that both humans and programs can read them ๐Ÿค–

Single line replies are a leading three-digit numeric code, then a space, then a one-line text explanation ๐Ÿฆ‹ For multi-line replies, the first line has the three-digit code immediately followed by the character "-" (Hyphen, ASCII code 45), and maybe some text. All succeeding continuation lines except the last are constrained NOT to begin with three digits, and the last line MUST repeat the numeric code of the first line and be followed immediately by a space ๐ŸŒธ For example:

100-First Line
Continuation Line
Another Line
100 Last Line

It is possible to nest (but not overlap) a reply within a multi-line reply ๐Ÿช† The same format for matched number-coded first and last lines holds too.

The numeric codes are assigned by groups, and for ease of interpretation by programs, they're consistent with other protocols like the RJE protocol ๐Ÿง  The three digits of the code are read like this:

  1. The first digit specifies the type of response:
  • 0xx These replies are purely informative and constitute neither a positive nor a negative acknowledgment. ๐Ÿซง
  • 1xx Informative replies to status inquiries. These constitute a positive acknowledgment to the status command. ๐Ÿ“Š
  • 2xx Positive acknowledgment of previous command or other successful action. โœ…
  • 3xx Incomplete information. Activity cannot proceed without further specification and input. โœ๏ธ
  • 4xx Unsuccessful reply. The request is correctly specified but the server is unsuccessful in correctly fulfilling it. ๐Ÿ’”
  • 5xx Incorrect or illegal command. The command or its parameters were invalid or incomplete from a syntactic viewpoint, or the command is inconsistent with a previous command. The command in question has been completely ignored. ๐Ÿ™…โ€โ™€๏ธ
  • 6xx-9xx Reserved for future expansion. ๐Ÿ”ฎ
  1. The second digit specifies the general category the response refers to:
  • x00-x29 General purpose replies, not assignable to other categories. ๐ŸŒท
  • x3x Primary access. Informative replies to the "log-on" attempt. ๐Ÿ”‘
  • x4x Secondary access. The primary server is commenting on its ability to access a secondary service. ๐Ÿ”—
  • x5x FTP results. ๐Ÿ“‚
  • x6x RJE results. ๐Ÿ—‚๏ธ
  • x7x Mail Protocol results. ๐Ÿ’Œ
  • x8x-x9x Reserved for future expansion. ๐Ÿ”ฎ
  1. The final digit specifies a particular message type. Since the code is designed for an automaton process to interpret, it is not necessary for every variation of a reply to have a unique number ๐Ÿค– Only the basic meaning of replies needs unique numbers. The text of a reply can explain the specific reason for that reply to a human user ๐Ÿ’ฌ

Each TELNET line delimited by a numeric code and the TELNET EOL (or group of text lines bounded by coded lines) that the server sends is intended to be a complete reply message ๐ŸŽฏ It SHOULD be noted that the text of replies is intended for a human user. Only the reply codes, and in some instances the first line of text, are intended for programs ๐Ÿ‘‘

The assigned reply codes relating to FTP are:

000  Announcing FTP.
010  Message from system operator.
020  Exected delay.
030  Server availability information.
050  FTP commentary or user information.
100  System status reply.
110  System busy doing...
150  File status reply.
151  Directory listing reply.
200  Last command received correctly.
201  An ABORT has terminated activity, as requested.
202  Abort request ignored, no activity in progress.
230  User is "logged in".  May proceed.
231  User is "logged out".  Service terminated.
232  Logout command noted, will complete when transfer done.
233  User is "logged out".  Parameters reinitialized.
250  FTP file transfer started correctly.
251  FTP Restart-marker reply.
   Text is:  MARK yyyy = mmmm
      where 'yyyy' is user's data stream marker (yours)
      and mmmm is server's equivalent marker (mine)
   (Note the spaces between the markers and '=').
252  FTP transfer completed correctly.
253  Rename completed.
254  Delete completed.
257  Closing the data connection, transfer completed.
300  Connection greeting message, awaiting input.
301  Current command incomplete (no <CRLF> for long time).
330  Enter password.
331  Enter account (if account required as part of login sequence).
332  Login first, please.
400  This service not implemented.
401  This service not accepting users now, goodbye.
402  Command not implemented for requested value or action.
430  Log-on time or tries exceeded, goodbye.
431  Log-on unsuccessful.  User and/or password invalid.
432  User not valid for this service.
433  Cannot transfer files without valid account.  Enter account and
     resend command.
434  Log-out forced by operator action.  Phone site.
435  Log-out forced by system problem.
436  Service shutting down, goodbye.
450  FTP:  File not found.
451  FTP:  File access denied to you.
452  FTP:  File transfer incomplete, data connection closed.
453  FTP:  File transfer incomplete, insufficient storage space.
454  FTP:  Cannot connect to your data socket.
455  FTP:  File system error not covered by other reply codes.
456  FTP:  Name duplication; rename failed.
457  FTP:  Transfer parameters in error.
500  Last command line completely unrecognized.
501  Syntax of last command is incorrect.
502  Last command incomplete, parameters missing.
503  Last command invalid (ignored), illegal parameter combination.
504  Last command invalid, action not possible at this time.
505  Last command conflicts illegally with previous command(s).
506  Last command not implemented by the server.
507  Catchall error reply.
550  Bad pathname specification (e.g., syntax error).

DECLARATIVE SPECIFICATIONS

MINIMUM IMPLEMENTATION

In order to make FTP workable without needless error messages, the following minimum implementation is REQUIRED for servers ๐Ÿ’–

TYPE - ASCII Non-print
MODE - Stream
STRUCTURE - File
            Record
BYTE - 8
COMMANDS - USER, BYE, SOCK,
           TYPE, BYTE, MODE, STRU,
             for the default values
           RETR, STOR,
           NOOP.

The initial default values for transfer parameters are:

TYPE - ASCII Non-print
BYTE - 8
MODE - Stream
STRU - File

All Hosts MUST accept the above as the standard defaults ๐ŸŒˆ

CONNECTIONS

The server protocol interpreter SHALL "listen" on Socket 3 ๐Ÿ”Œ The user or user protocol interpreter SHALL initiate the full-duplex TELNET connections, using the ARPANET standard initial connection protocol (ICP), to server Socket 3. Server- and user- processes SHOULD follow the conventions of the TELNET protocol as specified in NIC #7104. Servers are under no obligation to provide for editing of command lines, and they MAY specify that it be done in the user Host ๐Ÿซถ The TELNET connections SHALL be closed by the server at the user's request after all transfers and replies are completed ๐Ÿฆ‹

The user-DTP MUST "listen" on the specified data sockets (send and/or receive). These MAY be the default user sockets (U+4) and (U+5), or a socket specified in the SOCK command โœจ The server SHALL initiate the data connection from its own fixed sockets (S+2) and (S+3), using the specified user data socket and byte size (default - 8 bits). The direction of the transfer and the sockets used will be determined by the FTP service command ๐ŸŽ€

When data is to be transferred between two servers, A and B (refer to Figure 2), the user-PI, C, sets up TELNET connections with both server-PI's ๐Ÿ‘ฏ He then sends A's fixed sockets, S(A), to B in a SOCK command, and B's to A. Replies are returned. One of the servers, say A, is then sent a PASV command telling him to "listen" on his data sockets rather than initiate an RFC when he receives a transfer service command. When the user-PI receives an acknowledgment to the PASV command, he MAY send (in either order) the corresponding service commands to A and B. Server B initiates the RFC and the transfer proceeds ๐Ÿš€ The command-reply sequence is listed below, where the messages are vertically synchronous but horizontally asynchronous:

   User-PI - Server A                User-PI - Server B
   ------------------                ------------------

   C->A : ICP                        C->B : ICP
   C->A : SOCK HOST-B, SKT-S(B)      C->B : SOCK HOST-A, SKT-S(A)
   A->C : 200 Okay                   B->C : 200 Okay
   C->A : PASV
   A->C : 200 Okay
   C->A : STOR                       C->B : RETR

The data connection shall be closed by the server under the conditions described in the Section on Establishing Data Connections ๐Ÿ”’. If the server wants to close the connection after a transfer where it's not required, it should do that right after the file transfer is completed ๐Ÿƒโ€โ™€๏ธ. It should not wait until a new transfer command comes in, because the user-process will have already checked the data connection to see if it needs to do a "listen" (remember, the user has to "listen" on a closed data socket BEFORE sending the transfer request) ๐Ÿ˜ญ. To prevent a race condition here, the server sends a secondary reply (257) after closing the data connection. If the connection is left open instead, the server sends a "file transfer completed" reply (252), and the user-PI should wait for one of these replies before issuing a new transfer command ๐Ÿซถ.

COMMANDS โœจ

The commands are TELNET character strings sent over the TELNET connections, as described in the Section on FTP Commands ๐Ÿ’Œ. The command functions and semantics are covered in the Section on Access Control Commands, Transfer Parameter Commands, FTP Service Commands, and Miscellaneous Commands ๐Ÿ“š. The command syntax itself is specified right here.

Each command begins with a command code, followed by an argument field.

The command codes are four or fewer alphabetic characters, and upper and lower case are treated identically. So any of these can be the retrieve command ๐Ÿ’…:

   RETR    Retr    retr    ReTr    rETr

This also applies to symbols representing parameter values, like A or a for ASCII TYPE. The command codes and argument fields are separated by one or more spaces ๐ŸŒธ.

The argument field is a variable-length character string ending with the character sequence <CRLF> (Carriage Return, Linefeed) for NVT-ASCII representation. For other negotiated languages, a different end of line character might be used ๐ŸŒˆ. It's worth knowing that the server takes NO action until the end of line code is received ๐Ÿ™ˆ.

The syntax is specified below in NVT-ASCII. All characters in the argument field are ASCII characters, including any ASCII represented decimal integers. Square brackets denote an optional argument field, and if the option is not taken, the appropriate default is implied ๐ŸŽ€.

The following are all the currently defined FTP commmands โœจ:

   USER <SP> <username> <CRLF>
   PASS <SP> <password> <CRLF>
   ACCT <SP> <acctno> <CRLF>
   REIN <CRLF>
   BYE <CRLF>
   BYTE <SP> <byte size> <CRLF>
   SOCK <SP> <Host-socket> <CRLF>
   PASV <CRLF>
   TYPE <SP> <type code> <CRLF>
   STRU <SP> <structure code> <CRLF>
   MODE <SP> <mode code> <CRLF>
   RETR <SP> <pathname> <CRLF>
   STOR <SP> <pathname> <CRLF>
   APPE <SP> <pathname> <CRLF>
   ALLO <SP> <decimal integer> [<SP> R <SP> <decimal integer>] <CRLF>
   REST <SP> <marker> <CRLF>
   RNFR <SP> <pathname> <CRLF>
   RNTO <SP> <pathname> <CRLF>
   ABOR <CRLF>
   DELE <SP> <pathname> <CRLF>
   LIST [<SP> <pathname>] <CRLF>
   NLST  [<SP> <pathname>] <CRLF>
   SITE <SP> <string> <CRLF>
   STAT [<SP> <pathname>] <CRLF>
   HELP [<SP> <string>] <CRLF>
   NOOP <CRLF>

The syntax of the above argument fields (using BNF notation where applicable) is ๐Ÿค“:

   <username> ::= <string>
   <password> ::= <string>
   <acctno> ::= <string>
   <string> ::= <char>|<char><string>
   <char> ::= any of the 128 ASCII characters except <CR> and <LF>
   <marker> ::= <pr string>
   <pr string> ::= <pr char>|<pr char><pr string>
   <pr char> ::= any ASCII code 33. through 126., printable
      characters
   <byte size> ::= any decimal integer 1 through 255
   <Host-socket> ::= <socket>|<Host number>, <socket>
   <Host-number> ::= a decimal integer specifying an ARPANET Host.
   <socket> ::= decimal integer between 0 and (2**32)-1
   <form code> ::= N|T|C
   <type code> ::= A[<SP> <form code>]|E [SP> <form code>]|I|
   L <SP> <byte size>
   <structure code> ::= F|R
   <mode code> ::= S|B|C
   <pathname> ::= <string>

SEQUENCING OF COMMANDS AND REPLIES ๐Ÿฆ‹

The communication between the user and server is meant to be an alternating dialogue, like a good group chat ๐Ÿ’ฌ. The user issues an FTP command, and the server responds with a prompt primary reply. The user should wait for this initial primary success or failure response before sending any further commands.

Certain commands need a second reply too, so the user should wait for that one as well. These replies can report on the progress or completion of a file transfer, or on the closing of the data connection. They are secondary replies to file transfer commands ๐Ÿ“ฆ.

The third class of replies is informational and spontaneous. These can arrive at any time, so the user-PI should be ready to receive them. They're listed below as sponteneous ๐Ÿ‘€.

One important group of spontaneous replies is the connection greetings. Under normal circumstances, a server sends a 300 reply, "awaiting input", when the ICP is completed. The user should wait for this greeting before sending any commands. If the server can't accept input right away, it should send a 000 "announcing FTP" or a 020 "expected delay" reply immediately, and then a 300 reply when it's ready. That way the user knows not to hang up if there's a delay ๐Ÿ™.

The table below lists the alternative success and failure replies for each command. These must be strictly adhered to. A server may substitute text in the replies, but the meaning and action implied by the code numbers and by the specific command reply sequence cannot be altered ๐Ÿšซ.

                   COMMAND-REPLY CORRESPONDENCE TABLE

   COMMAND             SUCCESS         FAILURE

   USER                230,330         430-432,500-505,507
   PASS                230,330         430-432,500-507
   ACCT                230             430-432,500-507
   REIN                232,233         401,436,500-507
      Secondary Reply  300
   BYE                 231,232         500-505,507
   BYTE                200,331         402,500-505,507
   SOCK                200,331         500-505,507
   PASV                200,331         500-507
   TYPE                200,331         402,500-505,507
   STRU                200,331         500-505,507
   MODE                200,331         402,500-505,507
   RETR                250             402,433,450,451,454,455,457,
                                         500-505,507,550
      Secondary Reply  252,257         452
   STOR                250             402,433,451,454,455,457,
                                         500-505,507,550
      Secondary Reply  252,257         452,453
   APPE                250             402,433,451,454,455,457,500-507,
                                         550
      Secondary Reply  252,257         452,453
   ALLO                200,331         402,500-507
   REST                200,331         500-507
   RNFR                200             402,433,450,451,455,500-507,550
   RNTO                253             402,433,450,451,455,456,500-507,
                                         550
   ABOR                201,202,331     500-507
   DELE                254             402,433,450,451,455,500-507,550
   LIST                250             402,433,450,451,454,455,457,
                                         500-507,550
      Secondary Reply  252,257         452
   NLST                250             402,433,450,451,454,455,457,
                                         500-507,550
      Secondary Reply  252,257         452
   SITE                200,331         402,500-507
   STAT                100,110,        450,451,455,500-507,550
                         150,151,331
   HELP                030,050         500-507
   NOOP                200             500-505,507
   Spontaneous Replies 000,010,020,    400,401,434-436
                         300,301,251,255

TYPICAL FTP SCENARIOS ๐Ÿงš

TIP User wanting to transfer file from Host X to local printer ๐Ÿ–จ๏ธ

  1. The TIP user opens TELNET connections by ICP to Host X socket 3.
  2. The following commands and replies are exchanged:
   TIP                       HOST X

   <---------- 300 Awaiting input <CRLF>
   USER username <CRLF> ---------->
   <---------- 330 Enter Password <CRLF>
   PASS password <CRLF> ---------->
   <---------- 230 User logged in <CRLF>
   SOCK 65538 <CRLF> ---------->
   <---------- 200 Commmand received OK<CRLF>
   RETR this.file <CRLF> ---------->
      (Host X initiates data connection to TIP socket 65538,
       i.e., PORT 1 receive)
   <---------- 250 File transfer started <CRLF>
   <---------- 252 File transfer completed <CRLF>
   BYE<CRLF>         ---------->
   <---------- 231 User logged out <CRLF>
  1. Host X closes the TELNET and data connections.
Note: The TIP user should be in line mode.

User at Host U wanting to transfer files to/from Host S ๐Ÿ”

In general, the user communicates with the server through a mediating user-FTP process. Here's a typical scenario ๐Ÿ’–. In it, the user-FTP prompts are shown in parentheses, '---->' stands for commands from Host U to Host S, and '<----' stands for replies from Host S to Host U.

   LOCAL COMMANDS BY USER              ACTION INVOLVED

   ftp (host) multics<CR>         ICP to Host S, socket 3,
                                  establishing TELNET connections
                                  <---- 330 Awaiting input <CRLF>
   username Doe <CR>              USER Doe<CRLF>---->
                                  <---- 330 password<CRLF>
   password mumble <CR>           PASS mumble<CRLF>---->
                                  <---- 230 Doe logged in.<CRLF>
   retrieve (local type) ASCII<CR>
   (local pathname) test 1 <CR>   User-FTP opens local file in ASCII.
   (for.pathname) testp11<CR>     RETR test.p11<CRLF> ---->
                                  Server makes data connection to
   (U+4)
                                  <---- 250 File transfer starts
   <CRLF>
                                  <---- 252 File transfer
   complete<CRLF>
   type Image<CR>                 TYPE I<CRLF> ---->
                                  <---- 200 Command OK<CRLF>
   byte 36<CR>                    BYTE 36<CR>LF ---->
                                  <---- 200 Command OK<CRLF>
   store (local type) image<CR>
   (local pathname) file dump<CR> User-FTP opens local file in Image.
   (for.pathname) >udd>cn>fd<CR>  STOR >udd>cn>fd<CRLF> ---->
                                  <---- 451 Access denied<CRLF>
   terminate                      BYE <CRLF> ---->
                                  Server closes all connections.
๐Ÿ“ฆ where this page comes from