FTP stands for “File Transfer Protocol”. It is an application protocol in TCP/IP protocol stack. It follows client-server program where FTP client is on one side and FTP server is on another side. In this scenario the client is going to open the connection with the server. The interaction between FTP client and FTP server is based on the TCP/IP protocol of transport layer protocol to make it reliable.
Files are exchanged over the internet using FTP protocol. This protocol is secured with an SSL. FTP client machine is also called as Local machine which is connected to the server machine.
The local machine or FTP Client will download a file from the FTP server or upload a file from the FTP Client to the FTP Server.
Working of FTP Protocol:
Suppose the FTP Client is connected through a local area network when the FTP process is running. In this process think that the FTP Client wants to open a connection with a FTP Server. The FTP server is always listening on port number 21. Thus the FTP Client will open the connection with FTP server at port no. 21. We can say that it is a default port no. used by the FTP server. Now as the FTP client’s process is running to which an Operating System will assign a port no. say 1000. The purpose of this connection is to sent commands. For ex. This command can be either a request for a file from FTP server or upload a file to the FTP server. As soon as this command is send , the FTP server is going to open a new connection with the FTP Client as say port No. 1001. The operating system will check whether this port no. is used by another process or not. It is finds out that the port no is being used by another process then it will assign some other port no. to the process. Now here the connection is initiated by FTP Server at port no .21 for sending the requested file. Suppose the FTP Client has requested for the same file, then the file will be downloaded through this second connection. This same connection will also be used for uploading the data/ file. Thus first connection will be only for commands. We say that FTP is an out of bound protocol because it uses 2 connections or channels. One channel is used for commands and other for data. So it differentiates between data and commands.
There are 2 types of FTP : 1. Active FTP and 2. Passive FTP.
The difference between Active FTP and Passive FTP is in building access list permission or to deny access to the FTP server when you deal with data transfer.
We have a FTP client process and on the other side we have FTP server process and they are reachable across network. FTP client will always initiate the connection with the server at port no.21 and operating system will give a process no. to the client say at 4000. Whenever client will send command it automatically sends a socket which contains IP address and port no. After receiving it server is going to read the IP and Port for establishing a second connection. Server then opens the connection with the client at the given port no specified in the socket. And then sends the required data to the FTP client.
The problem with Active FTP is that the actual connection is made by the FTP server and not by the FTP client. FTP client only tells the server on at which port no it is listening and server thus connects back to that specified port. If we see from client side it will appear as an outside connection initiating and to this the Client may block.
This problem of a FTP server initiating a connection can be solved by using Passive FTP. In this case the both the connections are initiated by the FTP Client. It solves the problem of firewall filtering the requested data.
The FTP Client initiates the connection with FTP server on a command port and sends passive FTP command i.e. PASV. The server then sends a port no. which tells the FTP client to what port no. it is listening to for the data connection. The client then initiates a specified data connection from its port to the port mentioned by the FTP server. The FTP server then sends the ACK back to the client’s data port.