How to use FTP by command-line in Ubuntu

We shall discuss installing the FTP server and will show you a few examples of how to upload and download single and multiple files on your Linux system.

-Advertisement-

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
-Advertisement-

Next, let’s install the FTP server.

Step 1. Install the vsftpd package using the below command.

sudo apt-get install vsftpd

Install The vsftpd Package On Ubuntu
Install The vsftpd Package On Ubuntu

-Advertisement-

Step 2. Check the vsftpd status.

sudo service vsftpd status

Check The vsftpd Service Status
Check The vsftpd Service Status

As you can see from the above screenshot that the FTP server is active and running successfully.

-Advertisement-

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:

Add A Rule For The SSH
Add A Rule For The SSH

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:

Add Rule For Port 20
Add Rule For Port 20

sudo ufw allow 21/tcp

You may find the rule already added as the below output:

Add A Rule For Port 21
Add A Rule For Port 21

Step 3. Also lets open the ports for the passive FTP.

sudo ufw allow 40000:50000/tcp

Add Rule For Passive FTP Port
Add Rule For Passive FTP Port

Step 4. Now let’s enable the firewall if it is not already enabled.

sudo ufw enable

Enable Firewall
Enable Firewall

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.

Connect to Remote FTP Server
Connect to Remote FTP Server

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

Check Your Current Working Directory
Check Your Current Working Directory

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

Sample Output Of The ls Command
Sample Output Of The ls Command

Step 3. From the FTP server machine, try to create a directory and create some files in it like the below screenshot.

Created a directory called ftpdir
Created a directory called ftpdir

Step 4. From the FTP client machine, move to the newly created directory and list its content to download it on the client machine.

Go to the ftpdir to download the listed files
Go to the ftpdir to download the listed files

Step 5. Now let’s download a single file.

get download1

Download Single File From The Remote FTP Server
Download Single File From The Remote FTP Server

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.

Check The Downloaded File
Check The Downloaded File

Step 6. To download multiple files from the FTP server.

mget download*

Download Multiple Files
Download Multiple Files

And you can check the downloaded files as shown previously.

Check The Downloaded Files
Check The Downloaded Files

Step 7. From the client FTP machine, while you are connected to the FTP server create a directory like the below screenshot.

Create Directory To Upload Files to FTP Server
Create Directory To Upload Files to FTP Server

Move from your current directory to the newly created directory.

From FTP Server Move to The uploaddir
From FTP Server Move to The uploaddir

Step 8. Now let’s upload one single file to the FTP server.

put upload1

Upload One Single File To The FTP Server
Upload One Single File To The FTP Server

Step 9. To upload multiple files to the FTP server.

mput upload*

Upload Multiple Files To The FTP Server
Upload Multiple Files To The FTP Server

From the FTP server machine, you can check the uploaded files as below.

Check uploaded files
Check uploaded files

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.

-Advertisement-
Hend Adel
Hi! I'm Hend Adel, a freelancer technical geek with successful experience in Database, Linux and many other IT fields. I help to build solutions to suit business needs and creating streamlined processes. I love Linux and I'm here to share my skills via FOSS Linux! Thanks for reading my article.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,639FansLike
362FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

Top 20 Git Commands with Practical Examples

If you are here reading this post, there is a high probability that you have heard or interacted with Github, and you now want to learn Git. Before we continue with showing you some of the cool Git commands, let's understand the difference between Git and GitHub.

Top 10 New Features in Linux Kernel 5.7

Linus Torvalds has announced the release of Linux Kernel 5.7 after seven weeks of development. The release announcement comes as a piece of exciting news as it brings a host of new features for the hardware manufacturers as well as the developers.

How to install CMake on Ubuntu

CMake is a cross-platform free and open-source software tool designed to build, test, and package the software. CMake uses a simple platform and compiler-independent configuration files to control the software compilation process.

How to install Lightworks on Ubuntu

Even though Linux may not get a native installer of video editing software like Adobe Premiere or Final Cut Pro, that doesn't mean there are no industry standards tools available. Lightworks is non-linear editing (NLE) video mastering app for Windows, Linux, and macOS. Installing it on Ubuntu is simple due to deb package availability.

How to install DaVinci Resolve on Fedora

Davinci Resolve is a professional application used for color correction, video editing, visual effects, and motion graphics. It is one of the extensively used software by movie industries located in Hollywood.

The 10 Best Programming Languages for Hacking

One of the significant entities we have in Cyber Security is Ethical Hacking (ETH). It is the process of detecting and finding flaws or vulnerabilities in a system that a hacker would exploit.

MUST READ

Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.
Elementary OS 5.1 Hera has received a point release with a handful of new features and bug fixes, and we will be reviewing the significant changes in this article. For those new to elementary OS, this Ubuntu-based Linux distribution uses their inhouse built Pantheon desktop environment and AppCenter.

The 6 Best Download Managers for Fedora

It is a well-known fact that using download managers can help improve download speeds as compared to web browsers. Apart from the inbuilt download manager wget on Fedora, just as on any distribution that is based on GNU/Linux package, there are more options to explore.

Manjaro ‘Gellivara’ XFCE Edition (17.0.5) in 10 Screenshots

Want to take a quick virtual tour Manjaro XFCE edition instead of downloading GBs worth of ISO image and then making a Live USB of it? We will make it easy for you. Here are a series of screenshots of the important aspects of Manjaro Linux in XFCE edition. This is a light-weight edition, and aims to be fast and low on system resources. You will be amazed on how it is still visually appealing and user friendly.

How to clone hard disk on Linux using Clonezilla

Disk cloning refers to the process of copying data from one disk to another, thus creating a one-to-one copy of the drive. Technically, this process is possible using the copy-and-paste method.

VIDEO: MX Linux 19 Features and Desktop Tour

MX Linux is a Linux distribution based on Debian stable and using core antiX components. The distributions MX Tools is very popular among users and combined with other several ready-to-use tools, it is great for users who prefer to tweak their distro to their liking. In this video, we will take you through the features tour showing casing MX Linux 19.