FTP protocol

Mirjana's picture

FTP protocol basics

FTP stands for ‘File Transfer Protocol’ and it is an Internet service designed to establish a connection to a particular Internet server, so that users are able to transfer files (download) to their computer or to transfer (upload) their files to the server.
Client applications were originally interactive command-line tools with a standardized command syntax, but graphical user interfaces have been developed for all desktop operating systems in use today. FTP is also often used as an application component to automatically transfer files for program internal functions.
The FTP protocol also includes commands that can be used to execute operations on a remote computer; e.g., to show folder contents, change directories, create folders or delete files.

FTP as client/server protocol

FTP is based on the client/server model for communications between computers. In this model, a computer called a server runs a program that "serves" data to other computers. The other computers run client programs that request information and process the replies that the server sends.
Usually FTP servers listen on the well-known port number 21 for incoming connections from clients. A connection to this port from the FTP client forms the control stream on which commands are passed to the FTP server and responses are collected. FTP uses out-of-band control; it opens dedicated data connections on other port numbers. The parameters for the data streams depend on the specifically requested transport mode.

FTP command and data channels

The FTP protocol consists of two channels, the command channel and the data channel.  These channels are responsible for exchanging commands and data in an FTP client session.

  •  Command channel
The command channel is responsible for handling/accepting simple commands between FTP server and client.
The command channel is also responsible for sending replies back to the FTP client in response to client commands.
Command channel typically runs on port 21 for standard FTP and encrypted FTP that uses explicit SSL. Command port 990 is used for encrypted implicit SSL connection.
The USER and PASS commands used for authenticating an FTP user are examples of commands that are exchanged on the command channel. The command channel remains open until the client sends the QUIT command to disconnect or the server forcibly disconnects the client.

  •  Data channel
The data channel runs on temporary random ports listening on the server (passive mode) or on the client (active mode) and are responsible for exchanging data in the form of file transfers and directory listings. The LIST command used for getting a FTP server directory listing is an example of a command that opens a data channel. Unlike the command channel which remains alive during the entire FTP session, the data channel automatically shuts down once the transfer of data is complete.
The port on which the data channel is performed and additionally whether the client or server is responsible for opening this port depends on the data transfer mode used. There are two data transfer modes available in FTP. These data transfer modes are known as passive and active a.k.a non-passive.