File Transfer Protocol (FTP) is a commonly used networking protocol, used to transfer files between two computers. The protocol is based on a client-server architecture. One of the computers runs an FTP server program, while the other computer runs an FTP client program, which can download or upload files to the server computer based on permissions.

Usually, users accessing the FTP server need to authenticate with a username and password, however, the server can also be configured to allow access to anonymous users.

Almost all popular operating systems like Windows, GNU/Linux, Mac OS have an FTP server and client programs available. In this article, we will see how to setup an FTP server on a Ubuntu system.

Installation

In Ubuntu, the program vsftpd, which stands for Very Secure FTP Daemon is a popular FTP server program, which can be run as a daemon, i.e., as a background process, like most servers.

This program is available in Ubuntu standard repository. To install it, run:

sudo apt install vsftpd

Note: For Ubuntu versions < 14.04, use apt-get instead of apt.

After installation, the vsftpd daemon should start automatically. To check if it has started properly, run:

service vsftpd status

If the status is not Active, i.e., it has not started properly, run the following command to start it, and check the status again after running it to see if it is now Active.

sudo service vsftpd start

Configuration

The configuration file for vsftpd is /etc/vsftpd.conf. There are number of configuration options available here. We will change two options which are commonly required.

Open the file using either vim or any editor of your choice.

sudo vim /etc/vsftpd.conf

By default, anonymous access to the FTP server is not allowed. To allow anonymous access, we change the variable anonymous_enable from NO to YES in the file.

For anonymous access, a user with the name ftp is created during installation. The default directory for access to an anonymous user is /srv/ftp, which is actually the home directory of user ftp. Any files to be shared with anonymous users must be copied here.

If, the directory for anonymous access is to be changed, we need to change home directory of user ftp. To do this, run:

sudo usermod -d <directory_path> ftp

Similarly, by default write access, i.e., upload access, to the FTP server is not allowed. To enable it, we uncomment the line with variable write_enable=YES.

Save and exit the file. If you are using vim, press Escape to go to vim command mode, then type :wq and press Enter to save and exit the file.

We need to restart the FTP server daemon for these changes to take effect. To restart it, run:

sudo service vsftpd restart

Testing the Server

Most modern web browsers have built in support for accessing FTP servers, i.e., they can act as integrated FTP clients. They only support downloading files from the server though, and not uploading.

Download Test

Enter ftp://<ip_address> in the address bar of the browser to access the FTP server, where <ip_address> is the IP address, or domain name, of the FTP server. To test your local FTP server, enter ftp:://127.0.0.1

Note that since anonymous access was enabled, the server is showing us directory listing of the folder we enabled for anonymous access, viz. /srv/files/ftp.

Let us change the configuration file to disable anonymous access now and test access with user login.

sudo vim /etc/vsftpd.conf

Change the variable anonymous_enable to NO.

Save and exit the file. Restart the FTP server for these changes to take place.

sudo service vsftpd restart

Open the same URL again in browser (ftp://127.0.0.1).

As we can see, the server is now asking us to enter the username and password. Enter the credentials and press OK.

Now the directory listing is of the home directory of the logged-in user. In this case, it is /home/abhi.

Upload Test

Web browsers only allow download of files from FTP servers. To upload files to an FTP server, we access the server from a file explorer.

In Ubuntu, we will use the default file explorer, Nautilus. Open Nautilus by clicking the icon from the dock, or search it from Dash and open it.

Click on Other Locations at the very bottom.

At the very bottom, enter our FTP server URL(ftp:://127.0.0.1) in the Connect to Server input box, and press the ‘Connect’ button.

Mark the ‘Registered User’ checkbox, and enter the username and password. You can choose either of the three options for remembering the password entered above. Finally, press the ‘Connect’ button at the top of the window.

Now, we can easily copy or create file on the FTP server in the usual way we do in a file explorer. The FTP server appears on the left hand side as shown below.

Note: Even though vsftpd can be configured for write access to anonymous users, this his a huge security risk for the system and must never be used! Upload to FTP server must only be enabled for system users.

Conclusion

In this way we can setup a FTP server on Ubuntu. Make sure you try accessing this from another system in your network, in which case you will need to enter ftp://Your_IP_address instead of ftp://127.0.0.1 in the other system’s browser.

Note that most FTP server programs are secured to encrypt the transferred content using SSL/TLS (called FTPS) or using SSH FTP. vsftpd uses FTPS in its implementation.