RFC765 (FTP) [part 2 of 3]

Brian Kantor brian at sdcc3.UUCP
Sun Jan 6 10:25:49 AEST 1985




                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



         ALLOCATE (ALLO)

            This command may be required by some servers to reserve
            sufficient storage to accommodate the new file to be
            transferred.  The argument shall be a decimal integer
            representing the number of bytes (using the logical byte
            size) of storage to be reserved for the file.  For files
            sent with record or page structure a maximum record or page
            size (in logical bytes) might also be necessary; this is
            indicated by a decimal integer in a second argument field of
            the command.  This second argument is optional, but when
            present 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.  The ALLO command
            should be treated as a NOOP (no operation) by those servers
            which do not require that the maximum size of the file be
            declared beforehand, and those servers interested in only
            the maximum record or page size should accept a dummy value
            in the first argument and ignore it.

         RESTART (REST)

            The argument field represents the server marker at which
            file transfer is to be restarted.  This command does not
            cause file transfer but "spaces" over the file to the
            specified data checkpoint.  This command shall be
            immediately followed by the appropriate FTP service command
            which shall cause file transfer to resume.

         RENAME FROM (RNFR)

            This command specifies the file which is to be renamed.
            This command must be immediately followed by a "rename to"
            command specifying the new file pathname.

         RENAME TO (RNTO)

            This command specifies the new pathname of the file
            specified in the immediately preceding "rename from"
            command.  Together the two commands cause a file to be
            renamed.

         ABORT (ABOR)

            This command tells the server to abort the previous FTP
            service command and any associated transfer of data.  The




                                   28


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



            abort command may require "special action", as discussed in
            the Section on FTP Commands, to force recognition by the
            server.  No action is to be taken if the previous command
            has been completed (including data transfer).  The TELNET
            connection is not to be closed by the server, but the data
            connection must be closed.

            There are two cases for the server upon receipt of this
            command: (1) the FTP service command was already completed,
            or (2) the FTP service command is still in progress.

               In the first case, the server closes the data connection
               (if it is open) and responds with a 226 reply, indicating
               that the abort command was successfully processed.

               In the second case, the server aborts the FTP service in
               progress and closes the data connection, returning a 426
               reply to indicate that the service request terminated in
               abnormally.  The server then sends a 226 reply,
               indicating that the abort command was successfully
               processed.

         DELETE (DELE)

            This command causes the file specified in the pathname to be
            deleted at the server site.  If an extra level of protection
            is desired (such as the query, "DO you really wish to
            delete?"), it should be provided by the user-FTP process.

         CHANGE WORKING DIRECTORY (CWD)

            This command allows the user to work with a different
            directory or dataset for file storage or retrieval without
            altering his login or accounting information.  Transfer
            parameters are similarly unchanged.  The argument is a
            pathname specifying a directory or other system dependent
            file group designator.

         LIST (LIST)

            This command causes a list to be sent from the server to the
            passive DTP.  If the pathname specifies a directory, the
            server should transfer a list of files in the specified
            directory.  If the pathname specifies a file then the server
            should send current information on the file.  A null
            argument implies the user's current working or default




                                   29


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



            directory.  The data transfer is over the data connection in
            type ASCII or type EBCDIC.  (The user must ensure that the
            TYPE is appropriately ASCII or EBCDIC).

         NAME-LIST (NLST)

            This command causes a directory listing to be sent from
            server to user site.  The pathname should specify a
            directory or other system-specific file group descriptor; a
            null argument implies the current directory.  The server
            will return a stream of names of files and no other
            information.  The data will be transferred in ASCII or
            EBCDIC type over the data connection as valid pathname
            strings separated by <CRLF> or <NL>.  (Again the user must
            ensure that the TYPE is correct.)

         SITE PARAMETERS (SITE)

            This command is used by the server to provide services
            specific to his system that are essential to file transfer
            but not sufficiently universal to be included as commands in
            the protocol.  The nature of these services and the
            specification of their syntax can be stated in a reply to
            the HELP SITE command.

         STATUS (STAT)

            This command shall cause a status response to be sent over
            the TELNET connection in the form of 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 which
            case the server will respond with the status of the
            operation in progress, or it may be sent between file
            transfers.  In the latter case the command may have an
            argument field.  If the argument is a pathname, the command
            is analogous to the "list" command except that 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 associated with that specification.
            If no argument is given, the server should return general
            status information about the server FTP process.  This
            should include current values of all transfer parameters and
            the status of connections.







                                   30


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



         HELP (HELP)

            This command shall cause the server to send helpful
            information regarding its implementation status over the
            TELNET connection to the user.  The command may take an
            argument (e.g., any command name) and return more specific
            information as a response.  The reply is type 211 or 214.
            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)

            This command does not affect any parameters or previously
            entered commands. It specifies no action other than that the
            server send an OK reply.

      The File Transfer Protocol follows the specifications of the
      TELNET protocol for all communications over the TELNET connection.
      Since, the language used for TELNET communication may be a
      negotiated option, all references in the next two sections will be
      to the "TELNET language" and the corresponding "TELNET end of line
      code".  Currently one may take these to mean NVT-ASCII and <CRLF>.
      No other specifications of the TELNET protocol will be cited.

      FTP commands are "TELNET strings" terminated by the "TELNET end of
      line code".  The command codes themselves are alphabetic
      characters terminated by the character <SP> (Space) if parameters
      follow and TELNET-EOL otherwise.  The command codes and the
      semantics of commands are described in this section; the detailed
      syntax of commands is specified in the Section on Commands, the
      reply sequences are discussed in the Section on Sequencing of
      Commands and Replies, and scenarios illustrating the use of
      commands are provided in the Section on Typical FTP Scenarios.

      FTP commands may be partitioned as those specifying access-control
      identifiers, data transfer parameters, or FTP service requests.
      Certain commands (such as ABOR, STAT, QUIT) may be sent over the
      TELNET connection while a data transfer is in progress.  Some
      servers may not be able to monitor the TELNET and data connections
      simultaneously, in which case some special action will be
      necessary to get the server's attention.  The exact form of the
      "special action" is undefined; but the following ordered format is
      tentatively recommended:






                                   31


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



         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
      listed above should have no unusual effect.)

   FTP REPLIES

      Replies to File Transfer Protocol commands are devised to ensure
      the synchronization of requests and actions in the process of file
      transfer, and to guarantee that the user process always knows the
      state of the Server. Every command must generate at least one
      reply, although there may be more than one; in the latter case,
      the multiple replies must be easily distinguished.  In addition,
      some commands occur in sequential groups, such as USER, PASS and
      ACCT, or RNFR and RNTO.  The replies show the existence of an
      intermediate state if all preceding commands have been successful.
      A failure at any point in the sequence necessitates the repetition
      of the entire sequence from the beginning.

         The details of the command-reply sequence are made explicit in
         a set of state diagrams below.

      An FTP reply consists of a three digit number (transmitted as
      three alphanumeric characters) followed by some text.  The number
      is intended for use by automata to determine what state to enter
      next; the text is intended for the human user.  It is intended
      that the three digits contain enough encoded information that the
      user-process (the User-PI) will not need to examine the text and
      may either discard it or pass it on to the user, as appropriate.
      In particular, the text may be server-dependent, so there are
      likely to be varying texts for each reply code.

      Formally, a reply is defined to contain the 3-digit code, followed
      by Space <SP>, followed by one line of text (where some maximum
      line length has been specified), and terminated by the TELNET
      end-of-line code.  There will be cases, however, where the text is
      longer than a single line.  In these cases the complete text must




                                   32


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



      be bracketed so the User-process knows when it may stop reading
      the reply (i.e. stop processing input on the TELNET connection)
      and go do other things.  This requires a special format on the
      first line to indicate that more than one line is coming, and
      another on the last line to designate it as the last.  At least
      one of these must contain the appropriate reply code to indicate
      the state of the transaction.  To satisfy all factions it was
      decided that both the first and last line codes should be the
      same.

         Thus the format for multi-line replies is that the first line
         will begin with the exact required reply code, followed
         immediately by a Hyphen, "-" (also known as Minus), followed by
         text.  The last line will begin with the same code, followed
         immediately by Space <SP>, optionally some text, and the TELNET
         end-of-line code.

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

         The user-process then simply needs to search for the second
         occurrence of the same reply code, followed by <SP> (Space), at
         the beginning of a line, and ignore all intermediary lines.  If
         an intermediary line begins with a 3-digit number, the Server
         must pad the front to avoid confusion.

            This scheme allows standard system routines to be used for
            reply information (such as for the STAT reply), with
            "artificial" first and last lines tacked on.  In the rare
            cases where these routines are able to generate three digits
            and a Space at the beginning of any line, the beginning of
            each text line should be offset by some neutral text, like
            Space.

         This scheme assumes that multi-line replies may not be nested.
         We  have found that, in general, nesting of replies will not
         occur, except for random system messages (also called
         spontaneous replies) which may interrupt another reply.  System
         messages (i.e. those not processed by the FTP server) will NOT
         carry reply codes and may occur anywhere in the command-reply
         sequence.  They may be ignored by the User-process as they are
         only information for the human user.





                                   33


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



      The three digits of the reply each have a special significance.
      This is intended to allow a range of very simple to very
      sophisticated response by the user-process.  The first digit
      denotes whether the response is good, bad or incomplete.
      (Referring to the state diagram) an unsophisticated user-process
      will be able to determine its next action (proceed as planned,
      redo, retrench, etc.) by simply examining this first digit.  A
      user-process that wants to know approximately what kind of error
      occurred (e.g. file system error, command syntax error) may
      examine the second digit, reserving the third digit for the finest
      gradation of information (e.g. RNTO command without a preceding
      RNFR.)

         There are five values for the first digit of the reply code:

            1yz   Positive Preliminary reply

               The requested action is being initiated; expect another
               reply before proceeding with a new command.  (The
               user-process sending another command before the
               completion reply would be in violation of protocol; but
               server-FTP processes should queue any commands that
               arrive while a preceding command is in progress.)  This
               type of reply can be used to indicate that the command
               was accepted and the user-process may now pay attention
               to the data connections, for implementations where
               simultaneous monitoring is difficult.

            2yz   Positive Completion reply

               The requested action has been successfully completed.  A
               new request may be initiated.

            3yz   Positive Intermediate reply

               The command has been accepted, but the requested action
               is being held in abeyance, pending receipt of further
               information.  The user should send another command
               specifying this information.  This reply is used in
               command sequence groups.

            4yz   Transient Negative Completion reply

               The command was not accepted and the requested action did
               not take place, but the error condition is temporary and
               the action may be requested again.  The user should




                                   34


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



               return to the beginning of the command sequence, if any.
               It is difficult to assign a meaning to "transient",
               particularly when two distinct sites (Server and
               User-processes) have to agree on the interpretation.
               Each reply in the 4yz category might have a slightly
               different time value, but the intent is that the
               user-process is encouraged to try again.  A rule of thumb
               in determining if a reply fits into the 4yz or the 5yz
               (Permanent Negative) category is that replies are 4yz if
               the commands can be repeated without any change in
               command form or in properties of the User or Server (e.g.
               the command is spelled the same with the same arguments
               used; the user does not change his file access or user
               name; the server does not put up a new implementation.)

            5yz   Permanent Negative Completion reply

               The command was not accepted and the requested action did
               not take place.  The User-process is discouraged from
               repeating the exact request (in the same sequence).  Even
               some "permanent" error conditions can be corrected, so
               the human user may want to direct his User-process to
               reinitiate the command sequence by direct action at some
               point in the future (e.g. after the spelling has been
               changed, or the user has altered his directory status.)

         The following function groupings are encoded in the second
         digit:

            x0z   Syntax - These replies refer to syntax errors,
                  syntactically correct  commands that don't fit any
                  functional category, unimplemented or superfluous
                  commands.

            x1z   Information -  These are replies to requests for
                  information, such as status or help.

            x2z   Connections - Replies referring to the TELNET and data
                  connections.

            x3z   Authentication and accounting - Replies for the login
                  process and accounting procedures.

            x4z   Unspecified as yet






                                   35


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



            x5z   File system - These replies indicate the status of the
                  Server file system vis-a-vis the requested transfer or
                  other file system action.

         The third digit gives a finer gradation of meaning in each of
         the function categories, specified by the second digit.  The
         list of replies below will illustrate this.  Note that the text
         associated with each reply is recommended, rather than
         mandatory, and may even change according to the command with
         which it is associated.  The reply codes, on the other hand,
         must strictly follow the specifications in the last section;
         that is, Server implementations should not invent new codes for
         situations that are only slightly different from the ones
         described here, but rather should adapt codes already defined.

            A command such as TYPE or ALLO whose successful execution
            does not offer the user-process any new information will
            cause a 200 reply to be returned.  If the command is not
            implemented by a particular Server-FTP process because it
            has no relevance to that computer system, for example ALLO
            at a TOPS20 site, a Positive Completion reply is still
            desired so that the simple User-process knows it can proceed
            with its course of action.  A 202 reply is used in this case
            with, for example, the reply text:  "No storage allocation
            necessary."  If, on the other hand, the command requests a
            non-site-specific action and is unimplemented, the response
            is 502.  A refinement of that is the 504 reply for a command
            that IS implemented, but that requests an unimplemented
            parameter.

      Reply Codes by Function Groups

         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 implemented, superfluous at this site.
         502 Command not implemented
         503 Bad sequence of commands
         504 Command not implemented for that parameter
          
         110 Restart marker reply.








                                   36


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



            In this case the text is exact and not left to the
            particular implementation; it must read:
                 MARK yyyy = mmmm
            where yyyy is User-process data stream marker, and mmmm
            server's equivalent marker.  (note the spaces between
            markers and "=".)
         119 Terminal not available, will try mailbox.
         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.)
         215 <scheme> is the preferred scheme.
          
         120 Service ready in nnn minutes
         220 Service ready for new user
         221 Service closing TELNET connection
            (logged out 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 closed; transfer aborted.
         227 Entering Passive Mode.  h1,h2,h3,h4,p1,p2
          
         230 User logged in, 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.
         151 User not local; Will forward to <user>@<host>.
         152 User Unknown; Mail will be forwarded by the operator.
         250 Requested file action okay, completed.
         350 Requested file action pending further information
         450 Requested file action not taken:
            file unavailable (e.g. file busy)
         550 Requested action not taken:




                                   37


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



            file unavailable (e.g. file not found, no access)
         451 Requested action aborted: local error in processing
         551 Requested action aborted: page type unknown
         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>
         

      Numeric Order List of Reply Codes

         110 Restart marker reply.
            In this case the text is exact and not left to the
            particular implementation; it must read:
                 MARK yyyy = mmmm
            where yyyy is User-process data stream marker, and mmmm
            server's equivalent marker.  (note the spaces between
            markers and "=".)
         119 Terminal not available, will try mailbox.
         120 Service ready in nnn minutes
         125 Data connection already open; transfer starting
         150 File status okay; about to open data connection.
         151 User not local; Will forward to <user>@<host>.
         152 User Unknown; Mail will be forwarded by the operator.
         200 Command okay
         202 Command not implemented, superfluous at this site.
         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.)
         215 <scheme> is the preferred scheme.
         220 Service ready for new user
         221 Service closing TELNET connection
            (logged out if appropriate)
         225 Data connection open; no transfer in progress
         226 Closing data connection;
            requested file action successful (for example, file transfer
            or file abort.)
         227 Entering Passive Mode.  h1,h2,h3,h4,p1,p2




                                   38


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



         230 User logged in, proceed
         250 Requested file action okay, completed.
         331 User name okay, need password
         332 Need account for login
         350 Requested file action pending further information
         354 Start mail input; end with <CR><LF>.<CR><LF>
         421 Service not available, closing TELNET connection.
            This may be a reply to any command if the service knows it
            must shut down.]
         425 Can't open data connection
         426 Connection closed; transfer aborted.
         450 Requested file 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
         500 Syntax error, command unrecognized
            [This may include errors such as command line too long.]
         501 Syntax error in parameters or arguments
         502 Command not implemented
         503 Bad sequence of commands
         504 Command not implemented for that parameter
         530 Not logged in
         532 Need account for storing files
         550 Requested action not taken:
            file unavailable (e.g. file not found, no access)
         551 Requested action aborted: page type unknown
         552 Requested file action aborted:
            exceeded storage allocation (for current directory or
            dataset)
         553 Requested action not taken:
            file name not allowed
         

















                                   39


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



DECLARATIVE SPECIFICATIONS

   MINIMUM IMPLEMENTATION

      In order to make FTP workable without needless error messages, the
      following minimum implementation is required for all servers:

         TYPE - ASCII Non-print
         MODE - Stream
         STRUCTURE - File, Record
         COMMANDS - USER, QUIT, PORT,
                    TYPE, MODE, STRU,
                      for the default values
                    RETR, STOR,
                    NOOP.

      The default values for transfer parameters are:

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

      All Hosts must accept the above as the standard defaults.

   CONNECTIONS

      The server protocol interpreter shall "listen" on Port L.  The
      user or user protocol interpreter shall initiate the full-duplex
      TELNET connection.  Server- and user- processes should follow the
      conventions of the TELNET protocol as specified in the ARPA
      Internet Protocol Handbook.  Servers are under no obligation to
      provide for editing of command lines and may specify that it be
      done in the user Host.  The TELNET connection 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 port; this may be
      the default user port (U) or a port specified in the PORT command.
      The server shall initiate the data connection from his own default
      data port (L-1) using the specified user data port.  The direction
      of the transfer and the port used will be determined by the FTP
      service command.







                                   40


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



      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.  One of the servers, say A, is then sent a PASV
      command telling him to "listen" on his data port rather than
      initiate a connection when he receives a transfer service command.
      When the user-PI receives an acknowledgment to the PASV command,
      which includes the identity of the host and port being listened
      on, the user-PI then sends A's port, a, to B in a PORT command; a
      reply is returned.  The user-PI may then send the corresponding
      service commands to A and B.  Server B initiates the connection
      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 : Connect                    C->B : Connect
         C->A : PASV
         A->C : 227 Entering Passive Mode. A1,A2,A3,A4,a1,a2
                                           C->B : PORT A1,A2,A3,A4,a1,a2
                                           B->C : 200 Okay
         C->A : STOR                       C->B : RETR
                    B->A : Connect to HOST-A, PORT-a

      The data connection shall be closed by the server under the
      conditions described in the Section on Establishing Data
      Connections.  If the server wishes to close the connection after a
      transfer where it is not required, he should do so immediately
      after the file transfer is completed.  He should not wait until
      after a new transfer command is received because the user-process
      will have already tested the data connection to see if it needs to
      do a "listen"; (recall that the user must "listen" on a closed
      data port BEFORE sending the transfer request).  To prevent a race
      condition here, the server sends a reply (226) after closing the
      data connection (or if the connection is left open, a "file
      transfer completed" reply (250) and the user-PI should wait for
      one of these replies before issuing a new transfer command.












                                   41


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



   COMMANDS

      The commands are TELNET character string transmitted over the
      TELNET connections as described in the Section on FTP Commands.
      The command functions and semantics are described in the Section
      on Access Control Commands, Transfer Parameter Commands, FTP
      Service Commands, and Miscellaneous Commands.  The command syntax
      is specified here.

      The commands begin with a command code followed by an argument
      field.  The command codes are four or fewer alphabetic characters.
      Upper and lower case alphabetic characters are to be treated
      identically.  Thus any of the following may represent the retrieve
      command:

         RETR    Retr    retr    ReTr    rETr

      This also applies to any symbols representing parameter values,
      such as A or a for ASCII TYPE.  The command codes and the argument
      fields are separated by one or more spaces.

      The argument field consists of 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
      should be noted that the server is to take 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.  If the option is not taken, the appropriate
      default is implied.

















                                   42


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



      The following are the FTP commands:

         USER <SP> <username> <CRLF>
         PASS <SP> <password> <CRLF>
         ACCT <SP> <account information> <CRLF>
         REIN <CRLF>
         QUIT <CRLF>
         PORT <SP> <Host-port> <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>
         MLFL [<SP> <ident>] <CRLF>
         MAIL [<SP> <ident>] <CRLF>
         MSND [<SP> <ident>] <CRLF>
         MSOM [<SP> <ident>] <CRLF>
         MSAM [<SP> <ident>] <CRLF>
         MRSQ [<SP> <scheme>] <CRLF>
         MRCP <SP> <ident> <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>
         CWD <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>














                                   43


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



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

         <username> ::= <string>
         <password> ::= <string>
         <account information> ::= <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> ::= printable characters, any
                       ASCII code 33 through 126
         <byte size> ::= any decimal integer 1 through 255
         <Host-port> ::= <Host-number>,<Port-number>
         <Host-number> ::= <number>,<number>,<number>,<number>
         <Port-number> ::= <number>,<number>
         <number> ::= any decimal integer 0 through 255
         <ident> ::= <string>
         <scheme> ::= R | T | ?
         <form code> ::= N | T | C
         <type code> ::= A [<SP> <form code>]
                       | E [<SP> <form code>]
                       | I
                       | L <SP> <byte size>
         <structure code> ::= F | R | P
         <mode code> ::= S | B | C
         <pathname> ::= <string>























                                   44


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



   SEQUENCING OF COMMANDS AND REPLIES

      The communication between the user and server is intended to be an
      alternating dialogue.  As such, 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 further commands.

      Certain commands require a second reply for which the user should
      also wait.  These replies may, for example, report on the progress
      or completion of file transfer or the closing of the data
      connection.  They are secondary replies to file transfer commands.

      One important group of informational replies is the connection
      greetings.  Under normal circumstances, a server will send a 220
      reply, "awaiting input", when the connection is completed.  The
      user should wait for this greeting message before sending any
      commands.  If the server is unable to accept input right away, he
      should send a 120 "expected delay" reply immediately and a 220
      reply when ready.  The user will then know not to hang up if there
      is a delay.

      The table below lists 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 Sequences

         In this section, the command-reply sequence is presented.  Each
         command is listed with its possible replies; command groups are
         listed together.  Preliminary replies are listed first (with
         their succeeding replies indented and under them), then
         positive and negative completion, and finally intermediary
         replies with the remaining commands from the sequence
         following.  This listing forms the basis for the state
         diagrams, which will be presented separately.

            Connection Establishment
               120
                  220
               220
               421






                                   45


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



            Login
               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
            Logout
               QUIT
                  221
                  500
               REIN
                  120
                     220
                  220
                  421
                  500, 502
            Transfer parameters
               PORT
                  200
                  500, 501, 421, 530
               PASV
                  227
                  500, 501, 502, 421, 530
               MODE, TYPE, STRU
                  200
                  500, 501, 504, 421, 530
            File action commands
               ALLO
                  200
                  202
                  500, 501, 504, 421, 530
               REST
                  500, 501, 502, 421, 530
                  350





                                   46


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



               STOR
                  125, 150
                     (110)
                     226, 250
                     425, 426, 451, 551, 552
                  532, 450, 452, 553
                  500, 501, 421, 530
               RETR
                  125, 150
                     (110)
                     226, 250
                     425, 426, 451
                  450, 550
                  500, 501, 421, 530
               LIST, NLST
                  125, 150
                     226, 250
                     425, 426, 451
                  450
                  500, 501, 502, 421, 530
               APPE
                  125, 150
                     (110)
                     226, 250
                     425, 426, 451, 551, 552
                  532, 450, 550, 452, 553
                  500, 501, 502, 421, 530
               MLFL
                  125, 150, 151, 152
                     226, 250
                     425, 426, 451, 552
                  532, 450, 550, 452, 553
                  500, 501, 502, 421, 530
               RNFR
                  450, 550
                  500, 501, 502, 421, 530
                  350
               RNTO
                  250
                  532, 553
                  500, 501, 502, 503, 421, 530
               DELE, CWD
                  250
                  450, 550
                  500, 501, 502, 421, 530





                                   47


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



               ABOR
                  225, 226
                  500, 501, 502, 421
               MAIL, MSND
                  151, 152
                     354
                        250
                        451, 552
                  354
                     250
                     451, 552
                  450, 550, 452, 553
                  500, 501, 502, 421, 530
               MSOM, MSAM
                  119, 151, 152
                     354
                        250
                        451, 552
                  354
                     250
                     451, 552
                  450, 550, 452, 553
                  500, 501, 502, 421, 530
               MRSQ
                  200, 215
                  500, 501, 502, 421, 530
               MRCP
                  151, 152
                     200
                  200
                  450, 550, 452, 553
                  500, 501, 502, 503, 421
            Informational commands
               STAT
                  211, 212, 213
                  450
                  500, 501, 502, 421, 530
               HELP
                  211, 214
                  500, 501, 502, 421
            Miscellaneous commands
               SITE
                  200
                  202
                  500, 501, 530





                                   48


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



               NOOP
                  200
                  500 421















































                                   49


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



STATE DIAGRAMS

   Here we present state diagrams for a very simple minded FTP
   implementation. Only the first digit of the reply codes is used.
   There is one state diagram for each group of FTP commands or command
   sequences.

   The command groupings were determined by constructing a model for
   each command then collecting together the commands with structurally
   identical models.

   For each command or command sequence there are three possible
   outcomes: success (S), failure (F), and error (E). In the state
   diagrams below we use the symbol B for "begin", and the symbol W for
   "wait for reply".

   We first present the diagram that represents the largest group of FTP
   commands:

      
                               1,3    +---+
                          ----------->| E |
                         |            +---+
                         |
      +---+    cmd    +---+    2      +---+
      | B |---------->| W |---------->| S |
      +---+           +---+           +---+
                         |
                         |     4,5    +---+
                          ----------->| F |
                                      +---+
      

      This diagram models the commands:

         ABOR, ALLO, DELE, CWD, HELP, MODE, MRCP, MRSQ, NOOP, PASV,
         QUIT, SITE, PORT, STAT, STRU, TYPE.













                                   50


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



   The other large group of commands is represented by a very similar
   diagram:

      
                               3      +---+
                          ----------->| E |
                         |            +---+
                         |
      +---+    cmd    +---+    2      +---+
      | B |---------->| W |---------->| S |
      +---+       --->+---+           +---+
                 |     | |
                 |     | |     4,5    +---+
                 |  1  |  ----------->| F |
                  -----               +---+
      

      This diagram models the commands:

         APPE, LIST, MLFL, NLST, REIN, RETR, STOR.

   Note that this second model could also be used to represent the first
   group of commands, the only difference being that in the first group
   the 100 series replies are unexpected and therefore treated as error,
   while the second group expects (some may require) 100 series replies.

   The remaining diagrams model command sequences, perhaps the simplest
   of these is the rename sequence:

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




                                   51


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



   A very similar diagram models the Mail and Send commands:

      
                   ----  1
                  |    |
      +---+  cmd   -->+---+     2     +---+
      | B |---------->| W |---------->| E |
      +---+           +---+        -->+---+
                       | |        |
                3      | | 4,5    |
         --------------  ------   |
        |                      |  |   +---+
        |               ------------->| S |
        |              |   1,3 |  |   +---+
        |             2|  --------
        |              | |     |
        V              | |     |
      +---+   text    +---+ 4,5 ----->+---+
      |   |---------->| W |---------->| F |
      +---+           +---+           +---+
      

         This diagram models the commands:

            MAIL, MSND, MSOM, MSAM.

      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, recall that the last line must consist only of a single
      period.




















                                   52


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



   The next diagram is a simple model of the Restart command:

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


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

   We note that the above three models are similar, in fact the Mail
   diagram and the Rename diagram are structurally identical. The
   Restart differs from the other two only in the treatment of 100
   series replies at the second stage.





















                                   53


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



   The most complicated diagram is for the Login sequence:

      
                            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 |
      +---+           +---+------------->+---+





















                                   54


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



   Finally we present a generalized diagram that could be used to model
   the command and reply interchange:

      
               ------------------------------------
              |                                    |
      Begin   |                                    |
        |     V                                    |
        |   +---+  cmd   +---+ 2         +---+     |
         -->|   |------->|   |---------->|   |     |
            |   |        | W |           | S |-----|
         -->|   |     -->|   |-----      |   |     |
        |   +---+    |   +---+ 4,5 |     +---+     |
        |     |      |    | |      |               |
        |     |      |   1| |3     |     +---+     |
        |     |      |    | |      |     |   |     |
        |     |       ----  |       ---->| F |-----
        |     |             |            |   |
        |     |             |            +---+
         -------------------
              |
              |
              V
             End
      

























                                   55


                                                                        
June 1980                                                        IEN 149
File Transfer Protocol                                           RFC 765



TYPICAL FTP SCENARIO

   User at Host U wanting to transfer files to/from Host S:

   In general the user will communicate to the server via a mediating
   user-FTP process.  The following may be a typical scenario.  The
   user-FTP prompts are shown in parentheses, '---->' represents
   commands from Host U to Host S, and '<----' represents replies from
   Host S to Host U.

      LOCAL COMMANDS BY USER              ACTION INVOLVED

      ftp (host) multics<CR>         Connect to Host S, port L,
                                     establishing TELNET connections
                                     <---- 220 Service ready <CRLF>
      username Doe <CR>              USER Doe<CRLF>---->
                                     <---- 331 User name ok,
                                               need password<CRLF>
      password mumble <CR>           PASS mumble<CRLF>---->
                                     <---- 230 User logged in.<CRLF>
      retrieve (local type) ASCII<CR>
      (local pathname) test 1 <CR>   User-FTP opens local file in ASCII.
      (for.pathname) test.pl1<CR>    RETR test.pl1<CRLF> ---->
                                     <---- 150 File status okay;
                                           about to open data connection
                                     Server makes data connection
                                     to port U
      <CRLF>
                                     <---- 226 Closing data connection,
                                         file transfer successful<CRLF>
      type Image<CR>                 TYPE I<CRLF> ---->
                                     <---- 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> ---->
                                     <---- 450 Access denied<CRLF>
      terminate                      QUIT <CRLF> ---->
                                     Server closes all
                                     connections.











                                   56


                                                                        
IEN 149                                                        June 1980
RFC 765                                           File Transfer Protocol



CONNECTION ESTABLISHMENT

   The FTP control connection is established via TCP between the user
   process port U and the server process port L.  This protocol is
   assigned the service port 21 (25 octal), that is L=21.













































                                   57



More information about the Comp.sources.unix mailing list