File Transfer Protocol or FTP it is a protocol used to move files between computers. The FTP uses the client/server model. The server is always listening and waiting for FTP requests from other remote clients. When the server receives a request, it establishes a connection and handles the login.
During this tutorial, we are going to cover installing the FTP server and will show you some examples of how to upload and download single and multiple files.
Install FTP on Ubuntu
Before starting in the installation process of FTP, we need to ensure that the system is up-to-date using the following commands:
sudo apt update sudo apt upgrade
Next, let’s install the FTP server.
Step 1. Install the vsftpd package using the below command.
sudo apt-get install vsftpd
Step 2. Check the vsftpd status.
sudo service vsftpd status
As you can see from the above screenshot that the FTP server is active and running successfully.
Step 3. In case you need the vsftpd service to run automatically when the system starts up, you can use the command:
sudo service vsftpd enable
Now let’s move to the next section.
Configure The Firewall
After installing the required FTP server package, we need to perform some more configurations on the firewall.
Step 1. One of the basic configurations is adding a rule for the SSH, and this will prevent you from being locked out of by the server.
sudo ufw allow ssh
As you can, the output of the previous command will be something like the below screenshot:
Step 2. Now let’s open the 20 and 21 ports for FTP.
sudo ufw allow 20/tcp
The output of the previous command should be something like the below screenshot:
sudo ufw allow 21/tcp
You may find the rule already added as the below output:
Step 3. Also lets open the ports for the passive FTP.
sudo ufw allow 40000:50000/tcp
Step 4. Now let’s enable the firewall if it is not already enabled.
sudo ufw enable
To ensure that all of the previous rules have been added successfully, you can check the status of the firewall by running the below command:
sudo ufw status
Configure the vsftpd Configuration File
Some other few configurations needed to be done by editing the vsftpd configuration file which is found in “/etc/vsftpd.conf.”
Step 1. First and before editing the vsftpd configuration file, we need to take a backup from this configuration file.
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.backup-copy
Step 2. Open the vsftpd configuration file using your favorite editor; here we are going to use the vi editor.
sudo vi /etc/vsftpd.conf
Step 3. After opening the configuration file, you can search for the below settings, uncomment them and ensure that they have the right value.
write_enable=YES --> Allow the FTP users to write files to the FTP server. chroot_local_user=YES --> Prevent the FTP users from browsing outside their own home directory. local_enable=YES --> Allow local users to login through FTP. local_umask=022 --> Give the correct permissions to the uploaded files/directories.
There are a lot of settings in the vsftpd configuration file you can check them and decide which is best for you.
Step 4. After editing the vsftpd configuration file, save and quit it.
Step 5. Now we need to restart the vsftpd service to enable all the previous changes.
sudo service vsftpd restart
Test The FTP Server
To test the FTP server, you need to connect from another machine using the FTP client which is already installed on most of the Linux systems. In case the FTP client is not installed, you can install it using the command as follows:
sudo apt-get install ftp
Step 1. From the client machine, connect to the FTP server.
ftp 192.168.1.5
where the above IP is the FTP server machine IP.
As you can see from the previous screenshot when you try to login to the FTP server, by default, it suggests the local user that you can use to login. After you enter the username and password, you will get the successful login message.
Step 2. Now let’s try out some commands, check your current directory.
pwd
As you can see from the previous output, the “/” here means the home directory of the local user logged in which in our case is “hendadel.”
List the content of the current directory.
ls
Step 3. From the FTP server machine, try to create a directory and create some files in it like the below screenshot.
Step 4. From the FTP client machine, move to the newly created directory and list its content to download it on the client machine.
Step 5. Now let’s download a single file.
get download1
As you can see from the previous screenshot, the file has been downloaded successfully. You can find the downloaded file in your client’s machine logged in user home directory like below.
Step 6. To download multiple files from the FTP server.
mget download*
And you can check the downloaded files as shown previously.
Step 7. From the client FTP machine, while you are connected to the FTP server create a directory like the below screenshot.
Move from your current directory to the newly created directory.
Step 8. Now let’s upload one single file to the FTP server.
put upload1
Step 9. To upload multiple files to the FTP server.
mput upload*
From the FTP server machine, you can check the uploaded files as below.
That ends this tutorial where we have installed the FTP server and used it to upload and download files. For any further assistance, please leave a comment and we will be glad to help you.