Introduction to FTP and Server Configuration in Linux

Sahil Patel
7 min readMar 21, 2023

--

Contributors: — NIRMI Patel.

Introduction: -

FTP means File Transfer Protocol and it is the standard mechanism provided by the TCP/IP to copy a file from one host to another. File Transfer Protocol is a protocol present at the Application layer of the OSI Model.

The types of files transferred using the FTP are ASCII files, EBCDIC files, or image files.

It is also used for downloading files to computers from other servers.

Connections it establishes in computers: -

FTP differs from the other client/server applications as this protocol establishes two connections between the hosts.

  • Where one connection is used for the data transfer and is known as a data connection.
  • While the other connection is used to control information like commands and responses and this connection is termed a control connection.

1. 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.

2. 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.

Features of FTP: -

The following are the features offered by the File transfer protocol:

  • FTP is mainly used to transfer one file at a time.
  • Other actions performed by FTP are listing files, creating and deleting directories, deleting files, renaming files, and many more.
  • FTP also hides the details of individual computer systems.
  • FTP allows those files that have ownership and access restrictions.
  • It is a connection-oriented protocol.
  • FTP is a stateful protocol as in this the client establishes a control connection for the duration of an FTP session that typically spans multiple data transfers.
Photo by Jordan Harrison on Unsplash

PART 1: — Install and Configure FTP in Linux along with us

1. sudo apt update
2. sudo apt install -y vsftpd

Now we will update the vsftpd.conf file by adding the following: -

3. sudo nano /etc/vsftpd.conf

Once the following lines are added in the config file: -

Type CTRL + O to save the file and CTRL + X to exit the NANO editor.

listen=NO
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=Yes
pasv_enable=Yes
pasv_min_port=10000
pasv_max_port=10100
allow_writeable_chroot=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO

You can check personally whether these lines are added or uncommented in the config file by going to /etc/vsftpd.conf

If a firewall is running on your system, you will need to allow some FTP ports through it because you need to allow FTP Traffic. Issue the following commands in the Terminal to allow ports 20 and 21 and 30000–31000 (Passive ports range): -

4. sudo ufw allow 20/tcp
sudo ufw allow 21/tcp
(single command: sudo ufw allow 20:21/tcp)
sudo ufw allow 30000:31000/tcp

You can now verify whether the port has been allowed in the firewall or not using the following command in Terminal: sudo ufw status

Now the VSFTPD is configured and allowed in the firewall; now we can enable and run the VSFTPD services.

5. sudo systemctl enable vsftpd.service
6. sudo systemctl start vsftpd.service

If you need to restart the VSFTPD service after making any configuration changes, command in Terminal is: sudo systemctl restart vsftpd.service

Now verify that VSFTPD is active and running: -

7. sudo systemctl status vsftpd.service

Part 2: — Create FTP User and Test FTP Connection: -

Create a user account that will be used to test the FTP connection

8. sudo adduser <username>

It will directly ask you to add a password for the account used to test the FTP connection or you can also write: — sudo passwd <username>

Just like Windows has ipconfig similarly, Linux has ifconfig in short “interface configuration” utility for system/network administration in Unix/Linux operating systems to configure, manage, and query network interface parameters via command-line interface or in a system configuration scripts.

The “ifconfig” command is used for displaying current network configuration information, setting up an ip address, netmask, or broadcast address to a network interface, creating an alias for the network interface, setting up hardware address, and enable or disable network interfaces.

By performing ifconfig command, we can know the actual IP address of your FTP server.

Now that the account is created and the FTP server is ready to test we will connect the IP address of our Server.

9. ftp <ip-address>

You can also configure FTP Server in Windows, By using a client like Filezilla , In Linux Mint OS etc systems ! Go directly to References Section to check that out.

Part 3: — Transfer Files between Client and Server: -

From another user of the same computer: -

Successfully received hello.txt file from Client to Server.

From Client PC: -

Successfully received hello.txt file from Server (remote) to Client (local machine).

List of Commands for help while working and understanding FTP: -

  • help or ?— list all available FTP commands.
  • cd — change the directory on the remote machine.
  • lcd— change the directory on the local machine.
  • ls — list the names of the files and directories in the current remote directory.
  • mkdir— create a new directory within the current remote directory.
  • pwd — print the current working directory on the remote machine.
  • delete — remove a file in the current remote directory.
  • rmdir — remove a directory in the current remote directory.
  • get — copy one file from the remote to the local machine.
  • mget — copy multiple files from the remote to the local machine.
  • put — copy one file from the local to the remote machine.
  • mput — copy multiple files from the local to the remote machine.

Conclusion: -

  • File Transfer Protocol (FTP) is a standard network protocol used to transfer files between a client and a server on a computer network. It is a reliable and efficient way to transfer files over a network, especially when transferring large files or groups of files.
  • In Linux, FTP can be configured using various server applications such as vsftpd, proftpd, and pure-ftpd. These applications allow users to connect to the FTP server using a client application such as FileZilla or Cyberduck.
  • To transfer files using FTP in Linux, users need to first connect to the FTP server using their login credentials. Once connected, they can upload or download files to and from the server by navigating to the appropriate directories and using the appropriate commands.
  • Overall, FTP is a powerful tool for file transfer in Linux and is widely used in various industries for its reliability and efficiency. However, it is essential to ensure that FTP is configured securely to prevent unauthorized access or data breaches.

Thanks for reading, I hope you learnt something ! Any comments, doubts or suggestions are highly valuable to me.

Connect with me on LinkedIn here.

--

--