Prerequisite: Protocols in the Application Layer
File Transfer Protocol(FTP) is an application layer protocol that moves files between local and remote file systems. It runs on top of TCP, like HTTP. To transfer a file, 2 TCP connections are used by FTP in parallel: control connection and data connection.
Why FTP?
FTP is a standard communication protocol. There are various other protocols like HTTP which are used to transfer files between computers, but they lack clarity and focus as compared to FTP. Moreover, the systems involved in connection are heterogeneous systems, i.e. they differ in operating systems, directories, structures, character sets, etc the FTP shields the user from these differences and transfers data efficiently and reliably. FTP can transfer ASCII, EBCDIC, or image files. The ASCII is the default file share format, in this, each character is encoded by NVT ASCII. In ASCII or EBCDIC the destination must be ready to accept files in this mode. The image file format is the default format for transforming binary files.
Mechanism of File Transfer Protocol

Types of Connection in FTP
- Control Connection
- Data Connection

Types of Connection in FTP
1. Control Connection: For sending control information like user identification, password, commands to change the remote directory, commands to retrieve and store files, etc., FTP makes use of a control connection. The control connection is initiated on port number 21.
2. Data connection: For sending the actual file, FTP makes use of a data connection. A data connection is initiated on port number 20.
FTP sends the control information out-of-band as it uses a separate control connection. Some protocols send their request and response header lines and the data in the same TCP connection. For this reason, they are said to send their control information in-band. HTTP and SMTP are such examples.
FTP Session
When an FTP session is started between a client and a server, the client initiates a control TCP connection with the server side. The client sends control information over this. When the server receives this, it initiates a data connection to the client side. Only one file can be sent over one data connection. But the control connection remains active throughout the user session. As we know HTTP is stateless i.e. it does not have to keep track of any user state. But FTP needs to maintain a state about its user throughout the session.
FTP Clients
FTP works on a client-server model. The FTP client is a program that runs on the user’s computer to enable the user to talk to and get files from remote computers. It is a set of commands that establishes the connection between two hosts, helps to transfer the files, and then closes the connection.
Some of the commands are:
get the filename(retrieve the file from the server)
get the filename(retrieve multiple files from the server )
ls(list files available in the current directory of the server)
There are also built-in FTP programs, which makes it easier to transfer files and it does not require remembering the commands.
FTP Data Structures
FTP allows three types of data structures :
- File Structure: In file structure, there is no internal structure and the file is considered to be a continuous sequence of data bytes.
- Record Structure: In record structure, the file is made up of sequential records.
- Page Structure: In page structure, the file is made up of independent indexed pages.
FTP Commands
Some of the FTP commands are:
- USER – This command sends the user identification to the server.
- PASS – This command sends the user password to the server.
- 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.
- RMD – This command causes the directory specified in the path name to be removed as a directory.
- MKD – This command causes the directory specified in the pathname to be created as a directory.
- PWD – This command causes the name of the current working directory to be returned in the reply.
- RETR – This command causes the remote host to initiate a data connection and send the requested file over the data connection.
- STOR – This command causes the storage of a file in the current directory of the remote host.
- LIST – Sends a request to display the list of all the files present in the directory.
- ABOR – This command tells the server to abort the previous FTP service command and any associated transfer of data.
- QUIT – This command terminates a USER and if file transfer is not in progress, the server closes the control connection.
FTP Replies
Some of the FTP replies are :
- 200 – Command okay.
- 530 – Not logged in.
- 331 – User name okay, need a password.
- 225 – Data connection open; no transfer in progress.
- 221 – Service closing control connection.
- 551 – Requested action aborted: page type unknown.
- 502 – Command not implemented.
- 503 – Bad sequence of commands.
- 504 – Command not implemented for that parameter.
Characteristics of FTP
- FTP uses TCP as a transport layer protocol.
- It is good for simple file transfers, such as during boot time.
- Errors in the transmission (lost packets, checksum errors) must be handled by the TFTP server.
- It uses only one connection through well-known port 69.
- TFTP uses a simple lock-step protocol (each data packet needs to be acknowledged). Thus the throughput is limited.
Advantages of FTP
- Speed is one of the advantages of FTP(File Transfer Protocol).
- File sharing also comes in the category of advantages of FTP in this between two machines files can be shared on the network.
- Efficiency is more in FTP.
Disadvantages of FTP
- File size limit is the drawback of FTP only 2 GB size files can be transferred.
- Multiple receivers are not supported by the FTP.
- FTP does not encrypt the data this is one of the biggest drawbacks of FTP.
- FTP is unsecured we use login IDs and passwords making it secure but they can be attacked by hackers.
Anonymous FTP
Anonymous FTP is enabled on some sites whose files are available for public access. A user can access these files without having any username or password. Instead, the username is set to anonymous, and the password is to the guest by default. Here, user access is very limited. For example, the user can be allowed to copy the files but not to navigate through directories.
Please refer to the Active and Passive FTP article for more details.