FTP (File Transfer Protocol)
What is FTP ?
- FTP stands for File transfer protocol.
- FTP is a standard internet protocol provided by TCP/IP used for transmitting files from one host to another.
- It is mainly used for transferring web page files from their creator to the computer that acts as a server for other computers on the internet.
- It is also used for downloading files to computers from other servers.
Objectives of FTP
- It provides the sharing of files.
- It is used to encourage the use of remote computers.
- It transfers the data more reliably and efficiently.
Why FTP ?
Although transferring files from one system to another is very simple and straightforward, sometimes it can cause problems. For example, two systems may have different file conventions. Two systems may have different ways to represent text and data. Two systems may have different directory structures. FTP protocol overcomes these problems by establishing two connections between hosts. One connection is used for data transfer, and another connection is used for the control connection.
Mechanism of FTP
The above figure shows the basic model of the FTP. The FTP client has three components: the user interface, the control process, and the data transfer process. The server has two components: the server control process and the server data transfer process.
Types of Connection:
Control Connection:
The control connection uses very simple rules for communication. Through a control connection, we can transfer a line of command or line of response at a time. The control connection is made between the control processes. The control connection remains connected during the entire interactive FTP session.
Data Connection:
The Data Connection uses very complex rules as data types may vary. The data connection is made between data transfer processes. The data connection opens when a command comes for transferring the files and closes when the file is transferred.
FTP works in two different modes:
Active FTP Mode :
In active mode, the client connects on a random port for incoming data connections from the server. The client again sends the next port to the FTP server which is acknowledged on the command channel.
Passive FTP Mode :
In the passive mode, the client uses the control connection to send a PASV signal to the server. The FTP server sends back the IP address and server port number.
Implementing FTP Server-Client connection in Linux
To implement to connection setup we would take two different Linux VMs.
Step-1: There are many FTP servers to choose from like ProFTPD, vsftpd, etc. We will be using vsftpd.
To install vsftpd, type in the following command in your server machine.
sudo apt install vsftpd
Step-2: Configure Firewall
FTP uses port 20 for active mode, port 21 for commands, and a range of ports for passive mode. We need to open these ports from our firewall. Also, a client can use multiple ports to transfer multiple or a large file. We need to specify our FTP server to use those ports and that we will configure in FTP server. The ports till 1024 are reserved and our passive FTP port range should be higher than that.
sudo ufw allow 20/tcp
sudo ufw allow 21/tcp
sudo ufw allow 2000:8000/tcp
Step-3: Create isolated FTP directory and set permissions to it.
sudo mkdir /ftp
sudo chown [admin-username] /ftp
Step-4: FTP Server Configuration
Open the vsftpd configuration file.
sudo gedit /etc/vsftpd.conf
Make sure the following lines are uncommented
...
anonymous_enable=NO
local_enable=YES
write_enable=YES
...
As, we opened ports 2000 to 8000 in step-2 for passive mode, so now we will let vsftpd know which ports to use for passive FTP connection. Add the following lines in vsftpd.conf file.
pasv_min_port=2000
pasv_max_port=8000
Now, we will specify the default directory for FTP connections which will open when someone connects to our FTP server.
local_root=/ftp
Set permission for FTP users :
Uncomment following line of code to give access permissions.
local_umask=0002
After completing configuration, we need to restart our vsftpd server so that all these settings get applied immediately.
sudo systemctl restart vsftpd
Step-5: VMs Network Configuration
Make sure in network section of your both the VMs bridge mode is turned-on. This will allow both the VMs to communicated with each other.
Step-6: Client Call
Now, power-on your client machine and check for ftp package is install or not if not install it by type in
sudo apt install ftp
Now to connect the FTP server, type in
ftp [server-ip]
It would ask you for name type in server machine’s username and then password and Gotcha!, Congratulations you successfully logged in to FTP server. Now you can access files and directories of server machine.
FTP Clients
- FTP client is a program that implements a file transfer protocol that allows you to transfer files between two hosts on the internet.
- It allows users to connect to a remote host and upload or download the files.
- It has a set of commands that we can use to connect to a host, transfer the files between you and your host and close the connection.
- The FTP program is also available as a built-in component in a Web browser. This GUI-based FTP client makes the file transfer very easy and also does not require remembering the FTP commands.
Advantages of FTP
- Speed: One of the biggest advantages of FTP is speed. FTP is one of the fastest way to transfer files from one computer to another computer.
- Efficient: It is more efficient as we do not need to complete all the operations to get the entire file.
- Security: To access the FTP server, we need to login with the username and password. Therefore, we can say that FTP is more secure.
- Back & forth movement: FTP allows us to transfer the files back and forth. Suppose you are a manager of the company, you send some information to all the employees, and they all send information back on the same server.
Disadvantages of FTP
- The standard requirement of the industry is that all FTP transmissions should be encrypted. However, not all FTP providers are equal, and not all providers offer encryption. So, we will have to look out for FTP providers that provide encryption.
- Passwords and file contents are sent in clear text that allows unwanted eavesdropping. So, it is quite possible that attackers can carry out the brute force attack by trying to guess the FTP password.
- It is not compatible with every system.
Conclusion
FTP is a widely used protocol for transferring files between clients and servers over a network. While it has some security weaknesses, it remains an essential tool for many businesses and organizations that need to transfer large files or batches of files over the internet.