FTP and FTP Ports

File Transfer Protocol


What is FTP?


File Transfer Protocol (FTP) is a network protocol used in application layer of OSI Model or TCP/IP Model. With File Transfer Protocol (FTP), we can transfer files between two nodes that works as client and server. In other words, FTP is a file transfer protocol. And with such a working model, FTP is a Client/Server protocol.


FTP is not a secure file transfer protocol. Because, it uses clear-text password and username for file transfers. Instead of FTP, SFTP (SSH File Transfer Protocol) is used as a secure alternative. With SFTP, encrypted passwords and usernames are used.


With FTP we can do data transfer over FTP ports. For example, we can download a file to an FTP Client from a remote FTP Server. Or we can upload a file from FTP Client to FTP Server. As a summary, FTP is the general name of file transfer in network World


FTP uses two channels for file transfer. One of these channels is FTP control or FTP command channel. The other is FTP data channel. Different FTP ports are used for these channels.


The file transer with File Transfer Protocol is done over FTP ports. So, what are these ports of FTP?


What is an FTP Port?


As you know, there are various port types in network World. These ports are given below:


    Well-known Ports

    Registered Ports

    Dynamic Ports


Well-known ports are the network ports between 0 and 1024. And two of these well-known ports are used as FTP ports. The ports used for FTP are TCP port 20 and TCP port 21. But FTP data port is TCP port 20 for Active FTP connections. In Passive FTP mode, any random port can be used for data channel.


Beside FTP, there are also simpler protocol TFTP (Trivial File Transport Protocol) and more secure protocols, SFTP (SSH File Transfer Protocol), SCP (Secure Copy Protocol) and FTPS (FTP over SSL). TFTP uses UDP port 69, SFTP uses TCP port 22 and FTPS uses TCP port 990.  And SCP also uses TCP port 22. So, as a summary, ports of FTP are given below:


    FTP TCP Port 20,21

    TFTP UDP Port 69

    SFTP TCP Port 22

    SCP TCP Port 22

    FTPS TCP Port 990


So, why FTP uses two FTP ports? Because FTP need two stage processes. It is a TCP service that uses two ports. Here, firstly, user enters the login credentials in the FTP Client and the control FTP Server port is opened. The default port for this command is TCP port 21 of the server. After that the data transfer is done over TCP port 20 of the FTP server. In other words, the first ftp port, port 21 is the command port that provide the communication between two ends. The second ftp port, port 20 is the data transfer port.


FTP Active and Passive Mode Connections


We have learned what is FTP. And we have seen FTP ports for different File Transfer Protocols. Now, it is time to learn different connection modes of FTP.


There are two modes for FTP connections. These FTP modes are:


    Active mode

    Passive mode


So, what are these FTP modes? Let’s learn each of these modes.


FTP Active Mode


In Active mode FTP, firstly you need to check the FTP software. FTP active mode must be enabled on this software. Generally, active mode is enabled on the ftp softwares by default. So how ftp active modes work?


In Active mode, the client opens a random registered port. This can be any port from 1024 to 49151. For example, let’s say it select port 1024. FTP client starts a TCP three-way handshake connection and connects this port to FTP Server TCP port 21.


After that FTP client opens a data port which is one port above the previous one, here port 1025. And starts to listen the data channel. In other words, it waits FTP Server to initiate data channel.


ftp-active-mode-ipcisco


At this point, FTP Server initiates another TCP three-way handshake to the FTP Client from server TCP port 20 to the ftp client port 1025. After that, the file transfer starts.


As a summary, here, there are two different TCP three-way handshake connection. The first one is from FTP Client to FTP Server. From client port n to server port 21. The second one is from FTP Server to FTP client. From server port 20 to client port n+1.

 

FTP Passive Mode


FTP passive mode is the other mode of FTP connections. This mode is used to avoid Server initiated TCP three-way handshake. Because, in Active mode, this initiation can cause some failure on firewalls. In other words, firewall of the client can think that, this is an intrusion.


In Passive mode FTP, firstly, FTP passive mode must be enabled on the client. Because, generally it is not enabled by default.


In this mode, ftp client opens two registered ports as ftp ports. These ports of ftp must be above 1023. For example, port 1024 and 1025.


Here, the first one is used as control port and the second one is used as data port.


ftp-passive-mode-ipcisco


The client connects its command port to ftp port 21 of the ftp server. And it says to the server that it uses passive mode with PASV command. When server receives this message, it opens as registered port again, this can be port 1030 and then it informs the client. After that the client initiates TCP three-way handshake. In other words, the data transfer is started from clients ’s data port, port 1025, to the server data port, port 1030.


In this post, we have talked about FTP (File Transfer Protocol), FTP ports and FTP modes. We have learned ports of FTP with different FTP connections examples.


FTP Commands


In FTP operation, there are some main commands. We use these FTP commands and do FTP related jobs. So, what are these FTP commands? Below, you can find some of the commands of FTP:


 


   



Comments

Popular posts from this blog

Mastering IPv6 Static Routing in Packet Tracer: A Comprehensive Guide