Search

How FTP works

FTP (File Transfer Protocol) is one among the early developed protocols of TCP/IP protocol suite. FTP (File Transfer Protocol) is used to transfer files between an FTP Client and FTP Server. An end user sits at FTP Client computer and upload/download files to/from the File Systems of an FTP Server/FTP Client.

To understand how FTP works, please refer below image.

ftp-user-client-server.jpg

Before continuing further, please visit following lessons to understand the basics of FTP (File Transfer Protocol).

There are two different connection channels for FTP, one is used as Control channel and other one is used as Data channel. Commands and return codes are exchanged using Control channel and actual file transfer happens via Data channel.

FTP File operations

Mainly there are three types of operations in FTP.

  • File download from FTP Server to FTP Client : This is also called as retrieving a file. Internally RETR command is used to retrieve a file.

  • File upload from FTP Client to FTP Server : This is also called storing a file. Internally STOR command is used to store a file.

  • Remote directory listing : Listing the contents of the remote directory. Internally LIST command is used to list the contents of a remote directory.

FTP File structures

FTP STRU command is used to set file transfer structure. Following are the different file structures.

  • F (FILE structure) : FILE structure is a continuous stream of bytes.

  • R (RECORD structure) : Files divided into records, with fixed or variable length.

  • P (PAGE structure) : The file is divided into pages, with each page having a page number and a page header.

FTP Transmission Modes

Following are the different FTP Transmission Modes.

  • Stream mode : Transmission is made as continuous stream of bytes.

  • Block mode : Transmission is made as blocks. Each block is preceded by a three-byte header.

  • Compressed mode : Transmission with data compression.

FTP Transfer Types

Following are the different FTP Transfer Types.

  • TYPE A : ASCII, the default format for transferring text files.

  • TYPE E : EBCDIC.

  • TYPE I : Image, the default format for transferring binary files.

  • TYPE N : Nonprintable text files.

  • TYPE T : TELNET.

How FTP works - An example with capture screenshots

Following steps describe with capture screenshots of different commands and response codes used in a connection between FTP Client and FTP Server. The IP address of FTP Client is this example is 192.168.10.100 and FTP Server is 192.168.10.10.

Step 1 - After the initial TCP three-way handshake, FTP Server sends a Service Ready message to FTP Client.

how-ftp-works-01.jpg

Step 2 - FTP Client sends AUTH (Authentication) command (with TLS protection) to FTP Server.

how-ftp-works-02.jpg

Step 3 - FTP Server refuses TLS based Authentication, because TLS is not configured for use in FTP Server.

how-ftp-works-03.jpg

Step 4 - FTP Cient sends AUTH (Authentication) command (with SSL protection) to FTP Server.

how-ftp-works-04.jpg

Step 5 - FTP Server refuses SSL based Authentication, because SSL is also not configured for use in FTP Server.

how-ftp-works-05.jpg

Step 6 - FTP Client sends username for authentication in plain-text.

how-ftp-works-06.jpg

Step 7 - Username is okay, but password of the user jajish is also required for authentication.

how-ftp-works-07.jpg

Step 8 - FTP Client sends password for user jajish in plain-text. Both username and password are sent as plain-text, which is a high security risk.

how-ftp-works-08.jpg

Step 9 - User logged in.

how-ftp-works-09.jpg

Step 10 - SYST command (System Type) from FTP Client to FTP Server.

how-ftp-works-10.jpg

Step 11 - FTP Server replies with System Type.

how-ftp-works-11.jpg

Step 12 - FEAT command (Get feature list) from FTP Client to FTP Server.

how-ftp-works-12.jpg

Step 13 - FTP Server replies with feature list.

how-ftp-works-13.jpg

Step 14 - PWD command (Get current directory) from FTP Client to FTP Server.

how-ftp-works-14.jpg

Step 15 - FTP Server replies with current directory.

how-ftp-works-15.jpg

Step 16 - TYPE command (transfer type) from FTP Client to FTP Server. Refer FTP Transfer Types section for more details.

how-ftp-works-16.jpg

Step 17 - Transfer type set to Image (I), in this case.

how-ftp-works-17.jpg

Step 18 - PASV command (FTP Passive mode) from FTP Client to FTP Server.

how-ftp-works-18.jpg

Step 19 - FTP Server agrees for Passive mode. You can see that the FTP Server is using response code 227 for entering to passive mode. The server is also sending the IP address and port number to FTP Client, for making a new TCP connection for Data channel.

how-ftp-works-19.jpg

Step 20 - MLSD command from FTP Client to FTP Server to list directory. Now another TCP three-way handshake happens to open new TCP connection for Data channel.

how-ftp-works-20.jpg

Step 21 - Response code 150 is sent from FTP Server to FTP Client, to confirm about new Data channel.

how-ftp-works-21.jpg

Step 22 - Directory listing is sent from FTP Server to FTP Client, over the new Data channel.

how-ftp-works-22.jpg

Related Tutorials
What is FTP (File Transfer Protocol)
Important RFCs related with FTP
What is anonymous FTP
FTP Active vs Passive modes
Different types of FTP Client software
How to use FTP Active mode in FileZilla Client
FTP Commands
FTP Response Codes
Important commands in Windows command-line FTP client
Why FTP is not secure
Differences Between FTPS and SFTP
How to install FileZilla FTP Server
How to add a user in FileZilla FTP Server
How to add anonymous user account in FileZilla FTP Server
How to configure TLS (FTPS) in FileZilla FTP Server
Difference between Require explicit FTP over TLS and Require implicit FTP over TLS
How to install FileZilla FTP Client
How to login to a FTP Server using FileZilla FTP Client
FileZilla Site Manager
How to login to a FTP Server using Windows Command-line FTP Client