Creating a Simple FTP Server in RPI4

Zuber Kariye
7 min readFeb 16, 2022

Hello, everyone! It’s me again, i hope you are doing well.

Intro

In today’s blog, I will be walking you through the process of creating a simple FTP server using a small mini computer (RPI4). Let’s get into it.

Although FTP (File Transfer Protocol) is an old technology that was created a long time ago before even TCP and IP existed in 1971 and it is still used by lots of systems and hardware devices. Some IP cameras allow you to save photos to an FTP server and you can create one using a Raspberry Pi. If you’ve got the choice you would be better off using SFTP but if your device only supports FTP then this guide will help you create an FTP server.

FTP is a standard communication service that is used to transfers files from a server to a client on a computer network. FTP uses port 21for the command port and 20 for the data port. FTP was built in to be an insecure protocol since it was built in the ’90s. This protocol is generally considered to be an insecure protocol because it relies on a clear text credential (username and password) for authentication and it does not use encryption. Any data that is sent over FTP over a network is vulnerable to sniffing, spoofing, brute forcing, and many more other attacks using tools such as tcpdump, Wireshark, ettercap, bettercap, john2 for password brute-forcing. Enough intro about FTP, now let’s get into the technical stuff.

We will use vsftpd as it is a popular Linux application that is secure, stable, and extremely fast.

Initial Setup

You will need :

  • A Raspberry Pi
  • SD card with latest Raspbian image
  • Power supply
  • Keyboard and Monitor, mouse (optional)

I have an entire kit that had everything when i bought in 2020 from amazon. Here is the official link for that: https://www.amazon.com/Vilros-Raspberry-Fan-Cooled-Heavy-Duty-Aluminum/dp/B07XTRFD3Z/ref=sr_1_5?crid=26TBCMD1I53RL&keywords=rpi%2B4&qid=1644898655&sprefix=rpi%2B4%2B%2Caps%2C117&sr=8-5&th=1

I just set up a fresh operating system on my RPI4 which is the “raspbian” which is the default OS for this mini-computer.

If you need help setting up as well, I will suggest you look on the internet how this is done (YoutTube and Google).

Before I do anything, I need to enable and start the ssh server on the server (raspbian) so I can ssh from my client computer which makes things easier when setting this up.

First, let’s update and upgrade the system using these commands:

The first command: $ sudo apt update and $ sudo apt upgrade after that without the $ dollar sign. Luckily, everything was already up to date since this is a fresh system that i just installed.

Let’s now enable and start the ssh server on the system so we can remotely access it from our client machine. We will be using the “systemct” utility to accomplish this task, this tool basically controls and manages services on the system.

$ sudo systemctl status ssh

if the service is not enabled then start it with this command: $ sudo systemctl start ssh and put the password in the prompt. Let’s re-check the service by using one of our previous commands: $ sudo systemctl status ssh

The ssh service should be updated and running. Now I am going to ssh from my client(MacBook pro) to the RPI ssh server. Here is how it is done.

First, we need to get the IP address of the RPI machine by doing this so, $ ifconfig / ip a (new and latest command).

My IP address is something like this 192.168.1.94 which was assigned by the DHCP Server on my router. The default PI’s username is pi. Use this command to ssh remotely on the RPI machine. $ ssh pi@ip_add $ ssh pi@192.168.1.94 and enter when it prompted for the password of the PI machine.

I was getting an error while I was trying to login to the RPI machine using ssh from my MacBook, I solved this issue by adding keygen at a file in my MacBook. The command is: $ ssh-keygen -R (remote_host) — $ ssh-keygen -R 192.168.1.94

Then I was able to ssh into the machine. Now we are almost done with the setup and installation.

Step 1- Installing vsftpd

$ sudo apt install vsftpd

Once the installation is completed, edit the vsftpd configuration file using this command $ sudo nano /etc/vsftpd.conf and it looks like something like this

Step 2 - Update The Configuration File

The file is located in the /etc directory, navigate to there like so, $ sudo nano /etc/vsftpd.conf then edit and uncommon this few lines by removing the hashtag #.

anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
chroot_local_user=YES

Then add the following lines to the end.

user_sub_token=$USER
local_root=/home/$USER/ftp

Save and exit using CTRL-X, Y, and ENTER.

Step 3 - Create FTP Directory for the Pi User

To allow you to connect to the FTP server using the default Pi user we created we need to create a few directories:

mkdir /home/pi/ftp
mkdir /home/pi/ftp/files

Now let’s change their permission.

$ chmod a-w /home/pi/ftp

Step 4 - Create Ner User (Optional)

If you want to log into the server with a different or another user name then we can create a new user. In this example, we’ll create a new user called “test”.

$ sudo adduser test

You will be prompted for a password. Make sure it is a good one!

The other details can be left blank or populated as you see fit.

You should see something like this on your screen :

This new user will also need a set of FTP directories :

mkdir /home/camera/ftp
mkdir /home/camera/ftp/files

once created change the permission using:

$ sudo chmod a-w /home/test/ftp

This isn’t required for basic file transfer but the new user can be given the same ability to use “sudo” by running the command:

We are just given sudo permission to this new user named “test” so he can have some privileges on the system.

$ sudo adduser test sudo

Step 5 - Restart the FTP Server

Finally, restart the server using this command $ sudo systemctl restart vsftpd

Step 6 - Test the FTP Server

All that remains is to check you can connect to the server and transfer files.

Get your Pi’s IP address using:

$ ifconfig

Run your preferred FTP client on your PC/laptop. Windows users can use WinSCP. Windows, Mac, or Linux users can use FileZilla. If you have been connecting to the command line via SSH you may be able to use the same client for FTP. I am going to install client file transfer software (FileZilla).

Here is the official link to that -> https://filezilla-project.org/download.php?type=client

This is what it should look like, above!

Let’s connect to the server by entering the host / IP, username, password, and port number.

host: 192.168.1.95 | username: pi | password: Pi’s password | and 21 for the port number.

We got this message after we connected to the FTP Server.

As you can see, we received a message from FileZilla when we connected to the Server, this is just warning us that the server (FTP) is insecure and does not support TLS to encrypt the data.

Navigate into the “files” directory and you should be able to transfer files into it. If this works your FTP server is ready for whatever devices you wish to connect.

FTP Session Logs

You can check the vsftpd session logs to see a history of connections made to your FTP server.

$ cat /var/log/vsftpd.log

Let’s look at that right now and see if we received any connection from the client machine.

We did, of course, we got a connection from my MacBook and I use FileZilla as the client to connect to the FTP Server on the Pi.

Now we can do anything we want with this, we can download, drag and move files and folders around.

I hope you enjoy this and learn something valuable, new! Thank you for reading!

--

--

Zuber Kariye

Teen into computers and cybersecurity! Wannabe threat hunter, and pentester! Interested in programming, science and history!