TCP/IP For Internet Administrators
Previous Section Previous Page Query/Search Next Page Next Section

File Transfer Protocol (FTP)

The File Transfer Protocol (FTP) is used to transfer files from system to system across a network. It can transfer simple text files and convert between different native formats, such as from a Windows text format to a UNIX text format, or it can transfer raw Binary data, such as programs and graphical images, without modifying the information in the file. FTP can be used to transfer files of different structural types: file-structure, where there is no internal structure and the file is considered to be a continuous sequence of data bytes; record-structure, where the file is made up of sequential records; and page-structure, where the file is made up of independent indexed pages.

The FTP protocol originated as a simple procedure where a user would use Telnet to establish a link from one computer to another, start a file send or receive program on the remote system, then start the complementary receive or send program on the local system. The file(s) would then transfer across the Telnet link. The protocol evolved to mask the differences between various types of systems on a network so that the user was always presented with a familiar set of commands and responses, no matter what type of system was at the local or remote end of the link.

FTP is a TCP/IP application layer protocol that uses Transmission Control Protocol (TCP) to establish a reliable communication link between two systems. The protocol is documented in RFC 959. By default an FTP client application will contact the remote server using TCP port number 21 as the destination port, and will select at random a port from the dynamic or private range for the source port number. The remote server will normally respond by contacting the client system using the private port number as the destination and port number 21 as the source. This link is used to communicate commands and responses between the two systems. FTP also uses a second TCP communication link to transfer the file data between the two systems. This data link uses TCP port 20 as the destination port, and another randomly selected port from the dynamic or private range as the source port. The data link is established and terminated each time a file is transferred, while the communication link stay up through the entire session.

An FTP session normally begins by a client system contacting a server system. The client sends an ID and password to determine to the server to gain access to the servers file system. Then the client issues commands to navigate through the server file directories, list directory contents, and download or upload files. At the end of a session the client terminates the session. It is also a standard practice for an FTP server to automatically terminate a session if there is not activity for a preset length of time.

Many FTP server systems on the Internet will allow a client to log on using the ID “Anonymous”. Servers that allow an anonymous log in will normally request that the client give an E-Mail address for a password so that there is a way of identifying the user. This is most commonly done at sites that make libraries of files available for public use. Most systems that allow anonymous FTP only let the client download files from the server, or restrict uploads to a specific area.

FTP has a standardized set of commands. These are typically a three or four character command or abbreviation followed by an argument. A response message is returned by the server that consists of a numeric code followed by a text message. The success or failure status of the command can be determined from the numeric code. The text of the reply message also indicates success or failure, or gives information in addition to the numeric code.

The standard FTP commands are:

USER (User Name)
This is usually the first command transmitted after a link is established. The argument identifies the identity of the user for access to the servers file system. The server may respond by requesting additional validations in the form of a password and/or account information. The USER command may be used again at a later point in a session to change the access control identity of the user.

PASS (Password)
This command must follow immediately after a USER command and the argument completes the identification procedure. Not all systems will require a password, and some systems will require a password only for certain USER identities.

ACCT (Account)
This command provides additional information to identify a user to the file access system. It is not necessarily related to the USER command, and on may be required only for access to certain directories or for specific activities such as uploading files.

The FTP protocol uses a numeric code in the response to commands to specify whether or not ACCounT information is required. For example, when account information is required for login, the response to a successful PASSword command is reply code 332. If account information is NOT required for login, the reply to a successful PASSword command is 230. If account information is needed for a command issued later in the dialogue, the server should return a 332 if an ACCounT command should follow, or 532 if the command failed because of insufficient account privileges.

CWD (Change Working Directory)
This command allows the user to change to a different directory or data set for file storage or retrieval. The argument is a path name specifying a directory or other system dependent designator.

CDUP (Change to a Parent Directory / Change Directory Up)
This command is a special case of CWD, and was added to simplify the implementation of programs for transferring directory trees between operating systems having different syntax for naming parent directories. The reply codes are identical to the reply codes of CWD.

SMNT (Structure Mount)
This command allows the user to mount a file system data structure, such as mounting a tape or disk. The argument is a path name specifying a directory or other system dependent designator.

REIN (Reinitialize)
This command clears all USER and ACCT information on the current connection. It does not stop any transfer in progress, and does leave the communications link open. A USER command may be expected to follow.

QUIT (Log Out)
This command terminates a USER session and if file transfer is not in progress, the server closes the connection. If a file transfer is in progress, the connection will remain open until the transfer completes then the server will then close it.

PORT (Data Port)
This command is used to override the default Host and Port to be used for the Data connection of a file transfer. The argument is the 32 bit TCP/IP Address and 16 bit TCP Port Address, broken into 8-bit fields and separated by commas. A PORT command would be:

PORT h1,h2,h3,h4,p1,p2

where h1 is the high order 8 bits of the Internet host address.

PASV (Passive)
This command requests the server to "listen" on a data port that is not the default data port, and to wait for a connection rather than initiate one upon receipt of a transfer command. The response to this command includes the host and port address the server is listening on.

TYPE (Representation Type)
This command is used to specify the Data Representation Type. The argument identifies the type, such as A - ASCII, E - EBCDIC, I - Image. Some data types require a second parameter. Please consult the RFC for a detailed description of the arguments for this command.

STRU (File Structure)
This command identifies the structure to be used in file transfer. The argument is a single character code:
F - File (no record structure)
R - Record structure
P - Page structure

The default structure is File.

MODE (Transfer Mode)
This command identifies the transfer mode to be used in file transfer. The argument is a single character code:
S - Stream
B - Block
C - Compressed

The default transfer mode is Stream.

RETR (Retrieve)
This command instructs the server to send a copy of a file across the data communication link. The argument is a path name that identifies the file to be sent. This command is used to download a file from a remote server.

STOR (Store)
This command instructs a server to accept data across the communication link and store it as a file at the server site. The argument is a path name that identifies the destination and name of the file on the server site. If a file already exists on the server site with the same designation, it will be replaced by the contents of the data transmission. If the file does not exist, a new file is created. This command is used to upload a file to a remote server.

STOU (Store Unique)
This command is similar to the STOR command except that the file is saved in the current directory with a name that is unique to that directory. The response code will include the name of the file created.

APPE (Append with create)
This command is similar to the STOR command. If the file exists at the server site then the data is appended to the end of the existing file. IF the file does not exist, a new file is created.

ALLO (Allocate)
This command may be required by some servers to reserve storage for a file to be transferred. The argument is a decimal integer indicating the number of bytes of storage to be transferred. For files sent using record or page structure a maximum record or page size might also be required. This is indicated by a decimal integer in a second argument field. The second argument, if present, is separated from the first argument by three characters: Space, R, Space. This command is followed by a STOR or APPE command.

REST (Restart)
This command is used to cause a file transfer to begin at a point other than the start of a file. It does not start a file transfer but causes the server to skip through the file to the specified data checkpoint. The command should be immediately followed by the appropriate command to start the data transfer, such as STOR, RETR, or APPE.

RNFR (Rename From)
This command specifies a path name of a file to be renamed. This command is immediately followed by a “rename to” command.

RNTO (Rename To)
This command specifies a new path name of a file specified in the immediately preceding “rename from” command. Together the two commands cause a file to be renamed.

ABOR (Abort)
This command instructs the server to abort the previous file transfer command. If a data link is open and a transfer is in process, the transfer will be terminated, the server will return a 426 reply code indicating that the transfer terminated abnormally, the data link will be closed, and the server will respond with a 226 reply code indicating that the ABOR command completed successfully. If there is no data transfer currently in process, the data link is closed if it is open, and the server responds with a reply code of 226 indicating that the ABOR command completed successfully even though there was no action taken. The command link will be left open.

DELE (Delete)
This command causes the file specified in the argument to be deleted at the server site.

RMD (Remove Directory)
This command causes the directory specified in the argument to be removed at the server site. The path name in the argument may be absolute or relative to the current working directory.

MKD (Make Directory)
This command causes the directory specified in the argument to be created as a directory at the server site. The path name in the argument may be absolute or relative to the current working directory.

PWD (Print Working Directory)
This commands command causes the name of the current working directory to be returned in the reply.

LIST (List Directory)
This command causes a list of directory information to be sent from the server. If the argument specifies a directory, the contents of the directory are listed. If the argument specifies a filename, then information on that specific file is listed. If there is no argument, then the contents of the current working directory are listed.

NLST (Name List)
This command is similar to the LIST command. The argument should identify a directory and the server will return a list of file names. No other information will be returned.

SITE (Site Parameters)
This command is used by a server to identify services specific to that system that are essential to file transfer that may not be universal to the FTP protocol. The nature of these services will be described in a reply to the HELP SITE command.

SYST (System)
This command is used to find out the type of operating system at the server. The first word of the reply uses an Operating System Name from the Assigned Numbers document.

STAT (Status)
This command instructs the server to send a status response in the form of a reply message. The command may be sent during a file transfer 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 path name, the command treated as a LIST command except that data is transmitted transferred over the control connection. If a partial path name 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 returns general status information about the FTP process. This includes current values of all transfer parameters and the status of connections.

HELP (Help)
This command instructs the server to list the commands implemented on the server. A command may be given as an argument to get more information on that specific command.

NOOP (No Operation)
This command does not instruct the server to take any action except to send an OK reply. It does not affect any parameters or previously entered commands.

An FTP reply code consists of three digits, and is intended to make it easier for a program that is communicating with an FTP server to determine the result of the previous operation. The first digit tells whether the response if Good, Bad, or Incomplete. The second digit tells approximately what type of error occurred, and the third digit gives more specific information about the error.

The first digit of the reply code may have one of five values:

1 - Positive Preliminary reply: The requested action is started. Another reply will be generated on completion.

2 - Positive Completion reply: The requested action has been successfully completed.

3 - Positive Intermediate reply: The command has been accepted, but the requested action is on hold pending receipt of further information. The user should send another command specifying this information. This reply is used in command sequence groups like “Rename From” and “Rename To”..

4 - 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.

5 - 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).

The second digit of the reply code has five standard values:

0 - Syntax: These replies refer to syntax errors, syntactically correct commands that don't fit any functional category, and un-implemented or superfluous commands.

1 - Information: This indicates the reply is to a request for information, such as status or help.

2 - Connections: This indicates the reply refers to the control and data connections.

3 - Authentication and accounting: The reply is for the login process and accounting procedure.

4 - Unspecified

5 - File system: These replies indicate the status of the server file system. This normally refers to the requested transfer or other file system action.

The third digit of the reply code gives specific information in regard to the second digit.

The following is a list of standard reply codes:

120 Service ready in nnn minutes.

125 Data connection already open; transfer starting.

150 File status okay; about to open data connection.

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.

215 NAME system type, where NAME is an operating system name from the list in the Assigned Numbers document.

220 Service ready for new user.

221 Service closing control connection.

225 Data connection open; no transfer in progress.

226 Closing data connection.

227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).

230 User logged in, proceed.

250 Requested file action okay, completed.

257 "PATH NAME" created.

331 User name okay, need password.

332 Need account for login.

350 Requested file action pending further information.

421 Service not available, closing control connection.

425 Can't open data connection.

426 Connection closed; transfer aborted.

450 Requested file action not taken, file unavailable (busy)

451 Requested action aborted. Local error in processing.

452 Requested action not taken. Insufficient storage space in system.

500 Syntax error, command unrecognized.

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 (not found, no access).

551 Requested action aborted. Page type unknown.

552 Requested file action aborted. Exceeded storage allocation.

553 Requested action not taken. File name not allowed.

There are two common type of FTP client applications programs. The older, text oriented client programs require the user to enter the individual text commands, and display the responses from the remote system as they are received. The newer, graphical FTP client applications typically display a Graphical User Interface (GUI). The application generates the commands based on fields filled out and graphical controls used by the user. It then translates the replies from the remote and displays the information in the GUI. Most users who have experience with both types of client applications agree that the text applications are more flexible and the GUI FTP applications are generally easier to use for simpler tasks.

Previous Section Previous Page Query/Search Next Page Next Section