FTP - File Transfer Protocol
FTP is used for bulk data transfer across the Internet. Both FTP clients and servers are extremely common on UNIX machines.
The FTP client may be accessed from the command line:
host$ ftp machine_name
The standard FTP client recognizes the commands summarized in the table below (plus many others):
| FTP command || Purpose |
| List directory on remote machine. |
get file [ new]
| Retrieve file, and save it under name new (or same name, if new is omitted. |
| Transfer file from local machine to remote machine. |
| Use binary transfer mode (for data files). |
| Use ASCII transfer mode (for text files). |
| Change directory on remote machine (works like UNIX |
| Change directory on local machine (works like UNIX |
The FTP protocol:
FTP differs from other applications such as Telnet since it uses separate TCP connections for control and data. Recall that in Telnet both control information and data are sent over the same TCP connection using in-band signaling.
The two TCP connections in FTP are:
- The control connection is established in the normal client-server fashion. In this case, the server does a passive open (is listening) on port 21 for FTP, and waits for the client connection. The client does an active open (the 2nd handshake in a TCP connection) to establish the control connection. The client uses an ephemeral port number (above 1023) for the control connection. This control connection stays up for the entire time that the client communicates with this server. This connection is used for commands from the client to the server and for the server's replies. The IP type of service for the control connection should be to minimize delay in passing these commands over the TCP connection.
- A data connection is created each time a file is transferred between the client and the server. The IP type of service for the data connection should be to maximize throughput since this connection is file transfer, and we want to send this entire file over a high bandwidth line.
Specification of FTP
The specification of FTP includes more than 30 different commands, which are transmitted over the control connection in NVT ASCII format. The commands are not case-sensitive and may have arguments; each command ends with a two character sequence of a carriage return (CR) followed by a line feed (LF). It must be emphasized here that these commands are different from the commands typed by the user at the interface provided by the client. Transferring a single file for instance requires only a single user-level command (e.g., put or get), but this single command triggers the client to send a set of FTP commands to the server. The FTP server responds to each command with a three-digit reply code (for the FTP client) and an optional text message (for the user). The control connection persists over a sequence of FTP commands, as the client and the server continue their dialogue. The typical interaction starts with a command that identities the user on the server machine followed by another command to send the user password. The arguments for these commands are gleaned from the user's input (his account name and password). The server uses this information to verify whether the user has an authorized account on the remote machine, and in the case of anonymous FTP decides on the set of directories to which the anonymous guest has access. The next set of commands depend on the user request to send, receive, or view the files in a present directory.
Actual File Transfer
The actual file (data) transfer uses a separate TCP connection established by the host sending the data.
For instance if the user wants to retrieve the file exam1.pdf from the remote server, the server initiates the creation of the TCP data connection. In case, the user wants to put a file into the remote machine, it is the client who initiates the creation of the TCP connection. The data connection is usually established on port 20 on the server machine. In the former case (when the file is to be retrieved from the server), the server does not know the destination port for the FTP client. So before sending the command to retrieve the file, the client instructs its operating system to allocate a port number (above 1023) for such a transaction. This information is given to the server via the control connection. The data connection is created (using the usual TCP 3 way handshake), and the server writes the contents of the file, and closes the connection. The client reads the bytes from its socket upto the end of file (EOF) character. Also, unlike Telnet, FTP does not require the datatransfer to 7 bit ASCII characters (NVT format); it actually permits a wider range of data types including binary files. The client requests the form of data transfer using the control connection. In practice, each data transfer requires a separate TCP connection. In contrast, the control connection can persist across multiple data transfers. An example anonymous FTP session is shown in Section 26.10 of Comer. Use this session to distinguish between the control and data TCP connections. Also, can you identify our various discussions on the FTP protocol in this session?.
FTP Port numbers 20 and 21
The well-known port numbers for FTP are 20 and 21 (one for the control connection, one for data transfer).
File Transfer Protocol (FTP) is a standard network protocol used to transfer files from one host or to another host over a TCP-based network, such as the Internet. FTP is built on a client-server architecture and uses separate control and data connections between the client and the server.
FTP users may authenticate themselves using a clear-text sign-in protocol, normally in the form of a username and password, but can connect anonymously if the server is configured to allow it. For secure transmission that encrypts the username and password, and encrypts the content, FTP is often secured with SSL/TLS ("FTPS"). SSH File Transfer Protocol ("SFTP") is sometimes also used instead.
The first FTP client applications were command-line applications developed before operating systems had graphical user interfaces, and are still shipped with most Windows, Unix, and Linux operating systems. Dozens of FTP clients and automation utilities have since been developed for desktops, servers, mobile devices, and hardware, and FTP has been incorporated into hundreds of productivity applications, such as Web page editors.