RFC 640

Revised FTP reply codes

๐Ÿ“… published June 1974, from ietf

Revised FTP Reply Codes ๐ŸŽ€

RFC 640 ๐Ÿ’–

Jon Postel, 19 JUN 75 ๐ŸŒธ

Bestie, this doc is by Nancy Neigus, Ken Pogran, and Jon Postel (the authors' names are listed at the top and again at the end of the first part). It's dated 19 JUN 75. The header doesn't list a category or status, and it doesn't say it obsoletes anything. What it does say is that it modifies the protocol described in RFC 542 โœจ. So the protocol on socket number 21 (decimal) is the combination of RFC 542 and this RFC ๐Ÿงš.


This document is all about a revised set of reply codes for the File Transfer Protocol ๐Ÿฆ‹.

The goal here is pretty iconic. We want reply codes that let the command-issuing process easily figure out how each command turned out ๐Ÿ’…. The user protocol interpreter should be able to tell whether a command succeeded or failed just by looking at the first digit of the reply code ๐Ÿ”ฅ.

Okay, here's a big change to the order of commands and replies that you might not catch in the later docs. It has to do with how the data connection gets set up ๐Ÿ‘‘.

In the older FTP specs, when an actual transfer command (STOR, RETR, APPE, LIST, NLIST, MLFL) was issued, the preliminary reply got sent after the data connection was established. That was a problem for some user protocol interpreters because it was hard for them to watch two connections at the same time asynchronously ๐Ÿ˜ญ.
The current spec says the preliminary reply to the actual transfer commands tells you that the file can be transferred, and that either the connection was already set up or an attempt is about to be made to set it up ๐Ÿ’œ.

This reply code revision is a modification of the protocol described in RFC 542. That means the protocol implementation on socket number 21 (decimal) is the one specified by RFC 542 and this RFC together ๐ŸŒˆ.

Huge thanks to everyone who helped with this work: Ken Pogran, Mark Krilanovich, Wayne Hathway, and especially Nancy Neigus ๐Ÿซถ.

Nancy Neigus, Ken Pogran, Jon Postel, 19 JUN 75 ๐Ÿ“


A New Schema for FTP Reply Codes โœจ

Replies to File Transfer Protocol commands exist to keep requests and actions in sync during a file transfer, and to make sure the user process always knows the state of the Server ๐Ÿง . Every command has to generate at least one reply, though it can produce more than one. When it does, those multiple replies must be easy to tell apart ๐Ÿ’…. Some commands also come in sequential groups, like USER, PASS and ACCT, or RNFR and RNTO. The replies show an intermediate state exists when every command before it has succeeded. If something fails partway through, the whole sequence has to be repeated from the beginning ๐Ÿ˜ญ.

Details of the command-reply sequence will be made explicit in a state diagram ๐Ÿ—บ๏ธ.

An FTP reply is a three digit number (sent as three alphanumeric characters) followed by some text ๐ŸŽ€. The number is for automata to decide what state to go into next. The text is for the human user ๐Ÿ™ˆ. The three digits are supposed to carry enough encoded info that the user-process (the User-PI described in RFC 542) doesn't need to read the text at all. It can throw the text away or pass it along to the user, whichever makes sense โœจ. The text might depend on the server, so you'll probably see different text for each reply code ๐Ÿ’ซ.

Formally, a reply is the 3-digit code, then a space, <SP>, then one line of text (with some maximum line length specified), ending with the TELNET end-of-line code <eol>. Sometimes the text runs longer than one line ๐Ÿ“œ. In that case the whole text has to be bracketed so the User-process knows when to stop reading the reply (aka stop processing input on the TELNET connection) and go do other stuff ๐Ÿƒโ€โ™€๏ธ. That means the first line needs a special format to say more lines are coming, and the last line needs another format to say it's the last one ๐Ÿ”š. At least one of those lines must contain the right reply code so people know the state of the transaction ๐Ÿ”ฅ. To keep everyone happy, the first and last line codes are both the same ๐Ÿ’–.

So the multi-line format is this: the first line starts with the exact reply code, immediately followed by a Hyphen, "-" (also known as Minus), and then the text. The last line starts with the same code, immediately followed by a Space <SP>, then optionally some text, then TELNET <eol> ๐ŸŒธ.

For example:

123-First line
Second line
  234 A line beginning with numbers
123 The last line

The user-process only has to look for the second occurrence of the same reply code, followed by <SP>, at the start of a line, and ignore everything in between ๐Ÿงš. If a middle line starts with a 3-digit number, the Server has to pad the front of it so nothing gets confused ๐Ÿ›ก๏ธ.

This setup lets standard system routines handle reply info (like for the STAT reply), with "artificial" first and last lines tacked on ๐Ÿงฉ. In the rare cases where those routines can produce three digits and a Space at the start of any line, each text line should be offset by some neutral text, like a Space ๐Ÿซง.

This scheme assumes multi-line replies can't be nested ๐Ÿ™…โ€โ™€๏ธ. In general, nesting doesn't happen, except for random system messages (called spontaneous replies in earlier FTP versions) that can interrupt another reply ๐Ÿ˜ณ. Spontaneous replies aren't defined anymore. System messages (the ones the FTP server doesn't process) will NOT carry reply codes, and they can show up anywhere in the command-reply sequence ๐Ÿ™ˆ. The User-process can ignore them, since they're only info for the human user ๐Ÿ’….

The three digits of a reply each mean something specific ๐Ÿ”ข. This lets things range from super simple to super sophisticated on the user-process side โœจ. The first digit says whether the response is good, bad, or incomplete ๐Ÿ’ฏ. (Check the state diagram.) An unsophisticated user-process can decide its next move (keep going as planned, redo, back off, etc.) by just looking at that first digit ๐ŸŽฏ. A user-process that wants to know roughly what kind of error happened (like a file system error or a command syntax error) can look at the second digit. The third digit is kept for the finest level of detail, like an RNTO command with no RNFR before it ๐Ÿ”.

There are four possible values for the first digit of the reply code ๐ŸŒˆ:

  • 1yz Positive Preliminary reply ๐Ÿฆ‹

The requested action is starting up. Expect another reply before moving on to a new command. (If the user-process sends another command before the completion reply, that breaks protocol. Server-FTP processes should queue any commands that arrive while a previous command is still running.) This type of reply can tell the user-process that the command was accepted and it can now watch the data connections, for implementations where watching both at once is hard ๐Ÿ‘€.

  • 2yz Positive Completion reply ๐Ÿ’–

The requested action finished successfully. A new request can be started ๐ŸŽ‰.

  • 3yz Positive Intermediate reply ๐ŸŒ™

The command was accepted, but the requested action is on hold until more info arrives. The user should send another command giving that info. This reply is used in command sequence groups ๐Ÿ”—.

  • 4yz Transient Negative Completion reply โณ

The command wasn't accepted and the requested action didn't happen, but the error is temporary and the action can be requested again. The user should go back to the start of the command sequence, if there is one ๐Ÿ”. "Transient" is kind of a slippery word, especially when two separate sites (Server and User-processes) have to agree on what it means. Each reply in the 4yz category might have a slightly different time value, but the point is that the user-process is encouraged to try again ๐Ÿ’ช. Here's a rule of thumb for whether a reply is 4yz or 5yz (Permanent Negative): it's 4yz if the command can be repeated without changing the command form or the properties of the User or Server. For example, the command is spelled the same with the same arguments, the user doesn't change their file access or user name, and the server doesn't get a new implementation ๐Ÿง.

  • 5yz Permanent Negative Completion reply ๐Ÿšซ

The command wasn't accepted and the requested action didn't happen. The User-process is discouraged from repeating the exact same request (in the same sequence) ๐Ÿ™…. Even some "permanent" errors can be fixed, so the human user might want to tell their User-process to restart the command sequence later on, after something like a spelling fix or a change to their directory status ๐Ÿ› ๏ธ.

The second digit groups replies by function ๐Ÿ—‚๏ธ:

  • x0z Syntax ๐Ÿ’ป

These replies are about syntax errors, syntactically correct commands that don't fit any functional category, and unimplemented or superfluous commands ๐Ÿงพ.

  • x1z Information ๐Ÿ“š

These are replies to requests for information, like status or help ๐Ÿ’โ€โ™€๏ธ.


To be continued... ๐ŸŽ€โœจ

The second digit tells you the function group, and the third digit narrows it down, so these replies work like a little family tree ๐ŸŒณโœจ

x2z   Connections - Replies referring to the TELNET and
        data connections.
x3z   Authentication and accounting - Replies for the logon
        process and accounting procedures.
x4z   Unspecified as yet
x5z   File system - These replies indicate the status of
        the Server file system vis-a-vis the requested
        transfer or other file system action.

Okay so the third digit gives you a finer vibe within each function category that the second digit sets up ๐Ÿ’… The list below shows it off. The text attached to each reply is only suggestive, not mandatory, and it can even shift depending on which command it's answering ๐Ÿฆ‹ The reply codes, though? Those are strict. Server implementations should not invent brand-new codes for situations that are only slightly different from the ones described here. They should adapt the codes that already exist instead ๐Ÿซถ

If you really do need more codes, send the details to the FTP committee, through Jon Postel ๐Ÿ“ฎ

A command like TYPE or ALLO, where running it successfully doesn't give the user-process any new information, gets a 200 reply ๐ŸŒธ If a Server-FTP process doesn't implement the command because it has no relevance on that computer system (ALLO at a TENEX site, for example), a Positive Completion reply is still wanted, so the simple User-process knows it can keep going ๐Ÿ’– For that case you use 202, with reply text like "No storage allocation necessary." ๐Ÿงš If the command asks for something that isn't site-specific and it's unimplemented, the response is 502 ๐Ÿ’€ And 504 is the refinement for a command that IS implemented but asks for a parameter that isn't ๐Ÿ™ˆ

200  Command okay
500  Syntax error, command unrecognized
        [This may include errors such as command line too
        long.]
501  Syntax error in parameters or arguments
202  Command not imlemented, superfluous at this site.
502  Command not implemented
503  Bad sequence of commands
504  Command not implemented for that parameter

Now the 110 reply, which is the main one with strict text ๐Ÿ”ฅ The text here is exact and not left up to the implementation, so it has to read:

MARK yyyy = mmmm

Here yyyy is the User-process data stream marker, and mmmm is the Server's equivalent marker. (Note the spaces between the markers and "=".) ๐ŸŽ€

110  Restart marker reply.
211  System status, or system help reply
212  Directory status
213  File status
214  Help message (on how to use the server or the meaning
        of a particular non-standard command.  This reply
        is useful only to the human user.)
120  Service ready in nnn minutes
220  Service ready for new user
221  Service closing TELNET connection (logged off if
        appropriate)
421  Service not available, closing TELNET connection.
        [This may be a reply to any command if the service
        knows it must shut down.]

125  Data connection already open; transfer starting
225  Data connection open; no transfer in progress
425  Can't open data connection
226  Closing data connection; requested file action
        successful (for example, file transfer or file
        abort.)
426  Connection trouble, closed; transfer aborted.
227  Entering [passive, active] mode

230  User logged on, proceed
530  Not logged in
331  User name okay, need password
332  Need account for login
532  Need account for storing files

150  File status okay; about to open data connection.
250  Requested file action okay, completed.
350  Requested file action pending further information
450  Requested file action not taken: file unavailable
        (e.g. file not found, no access)
550  Requested action not taken:  file unavailable (e.g.
        file busy)
451  Requested action aborted: local error in processing
452  Requested action not taken:  insufficient storage
        space in system
552  Requested file action aborted:  exceeded storage
        allocation (for current directory or dataset)
553  Requested action not taken: file name not allowed
354  Start mail input; end with <CR><LF>.<CR><LF>

Command-Reply Sequences โœจ

Okay, this part is the sequence playbook ๐Ÿ“– Each command shows up with its possible replies, and commands in the same group are listed together ๐Ÿ’œ Preliminary replies come first (with their follow-up replies tucked under them), then positive and negative completion, and finally the intermediary replies plus whatever's left of the sequence. This listing is the basis for the state diagrams, which get presented separately ๐Ÿฆ‹

ICP

120
   220
220
421

Logon

USER
   230
   530
   500, 501, 421
   331, 332
PASS
   230
   202
   530
   500, 501, 503, 421
   332
ACCT
   230
   202
   530
   500, 501, 503, 421

Logoff

QUIT
   221
   500
REIN
   120
      220
   220
   421
   500, 502

Transfer parameters

SOCK
   200
   500, 501, 421, 530
PASV
   227
   500, 501, 502, 421, 530
ACTV
   227
   202
   500, 501, 421, 530
BYTE, MODE, TYPE, STRU
   200
   500, 501, 504, 421, 530

File action commands

          ALLO                                                          13e1
             200                                                       13e1a
             202                                                       13e1b
             500, 501, 504, 421, 530                                   13e1c
          REST                                                          13e2
             500, 501, 502, 421, 530                                   13e2a
             350                                                       13e2b
          STOR                                                          13e3
             125, 150                                                  13e3a
                (110)                                                 13e3a1
                226, 250                                              13e3a2
                425, 426, 451, 552                                    13e3a3
             532, 450, 452, 553                                        13e3b
             500, 501, 421, 530                                        13e3c
          RETR                                                          13e4
             125, 150                                                  13e4a
                (110)                                                 13e4a1
                226, 250                                              13e4a2
                425, 426, 451                                         13e4a3
             450, 550                                                  13e4b
             500, 501, 421, 530                                        13e4c
          LIST, NLST                                                    13e5
             125, 150                                                  13e5a
                226, 250                                              13e5a1
                425, 426, 451                                         13e5a2
             450                                                       13e5b
             500, 501, 502, 421, 530                                   13e5c
          APPE                                                          13e6
             125, 150                                                  13e6a
                (110)                                                 13e6a1
                226, 250                                              13e6a2
                425, 426, 451, 552                                    13e6a3
             532, 450, 550, 452, 553                                   13e6b
             500, 501, 502, 421, 530                                   13e6c
          MLFL                                                          13e7
             125, 150                                                  13e7a
                226, 250                                              13e7a1
                425, 426, 451, 552                                    13e7a2
             532, 450, 550, 452, 553                                   13e7b
             500, 501, 502, 421, 530                                   13e7c
          RNFR                                                          13e8
             450, 550                                                  13e8a
             500, 501, 502, 421, 530                                   13e8b
             350                                                       13e8c
          RNTO                                                          13e9
             250                                                       13e9a
             532, 553                                                  13e9b
             500, 501, 502, 503, 421, 530                              13e9c
          DELE                                                         13e10
             250                                                      13e10a
             450, 550                                                 13e10b
             500, 501, 502, 421, 530                                  13e10c
          ABOR                                                         13e11
             225, 226                                                 13e11a
             500, 501, 502, 421                                       13e11b
          MAIL                                                         13e12
             354                                                      13e12a
                250                                                  13e12a1
                451, 552                                             13e12a2
             450, 550, 452, 553                                       13e12b
             500, 501, 502, 421, 530                                  13e12c

       Informational commands                                            13f

          STAT                                                          13f1
             211, 212, 213                                             13f1a
             450                                                       13f1b
             500, 501, 502, 421, 530                                   13f1c
          HELP                                                          13f2
             211, 214                                                  13f2a
             500, 501, 502, 421                                        13f2b

       Miscellaneous commands                                            13g

          SITE                                                          13g1
             200                                                       13g1a
             202                                                       13g1b
             500, 501, 530                                             13g1c
          NOOP                                                          13g2
             200                                                       13g2a
             500                                                       13g2b

                                                           Jon Postel
                                                            19 JUN 75

FTP State Diagrams โœจ 14

Okay so here are the state diagrams for a super simple-minded FTP implementation ๐Ÿงš Only the first digit of the reply codes gets looked at, and there's one diagram for each group of FTP commands or command sequences ๐Ÿ’… 15

The groups were made by building a model for each command, then bundling together the commands with structurally identical models ๐ŸŽ€ 16

For every command or command sequence there are three possible outcomes: success (S), failure (F), and error (E). In the diagrams below, B means "begin" and W means "wait for reply" ๐Ÿ’– 17

First up is the diagram for the biggest group of FTP commands ๐Ÿ‘‘ 18

                            1,3    +---+
                       ----------->! E !
                      !            +---+
                      !
   +---+    cmd    +---+    2      +---+
   ! B !---------->! W !---------->! S !
   +---+           +---+           +---+
                      !
                      !     4,5    +---+
                       ----------->! F !
                                   +---+
                                                                     18a

This diagram models the commands: 18b

      ABOR, ACTV, ALLO, BYTE, DELE, HELP, MODE, NOOP, PASV, QUIT,
      SITE, SOCK, STAT, STRU, TYPE.                                 18b1

The other big group is shown by a very similar diagram ๐Ÿฆ‹ 19

                            3      +---+
                       ----------->! E !
                      !            +---+
                      !
   +---+    cmd    +---+    2      +---+
   ! B !---------->! W !---------->! S !
   +---+       --->+---+           +---+
              !     ! !
              !     ! !     4,5    +---+
              !  1  !  ----------->! F !
               -----               +---+
                                                                     19a

This diagram models the commands: 19b

      APPE, (ICP), LIST, MLFL, NLST, REIN, RETR, STOR.              19b1

Ngl, this second model could also be used for the first group ๐Ÿ™ˆ The only difference is that in the first group, the 100 series replies are unexpected and get treated as errors, while the second group expects (some may require) 100 series replies 20

The rest of the diagrams model command sequences. The simplest one is the rename sequence ๐ŸŒธ 21

   +---+   RNFR    +---+    1,2    +---+
   ! B !---------->! W !---------->! E !
   +---+           +---+        -->+---+
                    ! !        !
             3      ! ! 4,5    !
      --------------  ------   !
     !                      !  !   +---+
     !               ------------->! S !
     !              !   1,3 !  !   +---+
     !             2!  --------
     !              ! !     !
     V              ! !     !
   +---+   RNTO    +---+ 4,5 ----->+---+
   !   !---------->! W !---------->! F !
   +---+           +---+           +---+
                                                                     21a

A very similar diagram models the Mail command ๐Ÿ“ 22

   +---+   MAIL    +---+    1,2    +---+
   ! B !---------->! W !---------->! E !
   +---+           +---+        -->+---+
                    ! !        !
             3      ! ! 4,5    !
      --------------  ------   !
     !                      !  !   +---+
     !               ------------->! S !
     !              !   1,3 !  !   +---+
     !             2!  --------
     !              ! !     !
     V              ! !     !
   +---+   text    +---+ 4,5 ----->+---+
   !   !---------->! W !---------->! F !
   +---+           +---+           +---+
                                                                     22a

Note that the "text" here is a series of lines sent from the user to the server, with no response expected until the last line is sent. Remember, the last line must consist only of a single period. 22b

The next one is a simple model of the Restart command โœจ 23

   +---+   REST    +---+    1,2    +---+
   ! B !---------->! W !---------->! E !
   +---+           +---+        -->+---+
                    ! !        !
             3      ! ! 4,5    !
      --------------  ------   !
     !                      !  !   +---+
     !               ------------->! S !
     !              !   3   !  !   +---+
     !             2!  --------
     !              ! !     !
     V              ! !     !
   +---+   cmd     +---+ 4,5 ----->+---+
   !   !---------->! W !---------->! F !
   +---+        -->+---+           +---+
               !      !
               !  1   !
                ------
                                                                     23a

Where "cmd" is APPE, STOR, RETR, or MLFL. 23a1

We noticed the above three models are giving a whole family resemblance ๐Ÿ‘ฏ, because the Mail diagram and the Rename diagram are structurally identical ๐Ÿ’– The Restart is only different from the other two in how it treats 100 series replies at the second stage ๐ŸŽ€ 24

The most complicated diagram is for the Logon sequence, and it is lowkey spaghetti ๐Ÿ 25

                         1
   +---+   USER    +---+------------->+---+
   ! B !---------->! W ! 2       ---->! E !
   +---+           +---+------  !  -->+---+
                    ! !       ! ! !
                  3 ! ! 4,5   ! ! !
      --------------   -----  ! ! !
     !                      ! ! ! !
     !                      ! ! ! !
     !                 ---------  !
     !               1!     ! !   !
     V                !     ! !   !
   +---+   PASS    +---+ 2  !  ------>+---+
   !   !---------->! W !------------->! S !
   +---+           +---+   ---------->+---+
                    ! !   ! !     !
                  3 ! !4,5! !     !
      --------------   --------   !
     !                    ! !  !  !
     !                    ! !  !  !
     !                 -----------
     !             1,3!   ! !  !
     V                !  2! !  !
   +---+   ACCT    +---+--  !   ----->+---+
   !   !---------->! W ! 4,5 -------->! F !
   +---+           +---+------------->+---+
                                                                     25a

Finally, we present a generalized diagram that could be used to model the command and reply interchange, and honestly it's the blueprint for the whole vibe ๐Ÿฆ‹ 26

            ------------------------------------
           !                                    !
   Begin   !                                    !
     !     V                                    !
     !   +---+  cmd   +---+ 2         +---+     !
      -->!   !------->!   !---------->!   !     !
         !   !        ! W !           ! S !-----!
      -->!   !     -->!   !-----      !   !     !
     !   +---+    !   +---+ 4,5 !     +---+     !
     !     !      !    ! !      !               !
     !     !      !   1! !3     !     +---+     !
     !     !      !    ! !      !     !   !     !
     !     !       ----  !       ---->! F !-----
     !     !             !            !   !
     !     !             !            +---+
      -------------------
           !
           !
           V
          End
๐Ÿ“ฆ where this page comes from