How to Setup FTP on the Raspberry Pi

In this guide, we are going to take a look at setting up FTP on the Raspberry Pi. Setting up FTP will allow for easy transferring of files to and from your Pi over a network.

Raspberry Pi FTP

For those who don’t know, FTP stands for File Transfer Protocol and is simply a method for transferring files between two devices over a network

There is also an additional method that you can be used instead. This method is called SFTP, it stands for Secure File Transfer Protocol. This version of the protocol works over SSH.

The biggest difference between these two methods comes down to their security. SFTP is considered to be much more secure thanks to its use of encryption for the transfer of data.

We should also note that it is possible to use both FTP and SFTP at the same time as they operate on difference ports. By default FTP operates on port 21, while SFTP operates on port 22.

Using FTP is a great way to move files on and off of the Raspberry Pi without needing any fancy setups or physical access to the device itself.

Setting up SFTP is a very straightforward process as it is part of the SSH standard.

Using FTP requires a few more steps but is also fairly simple to set up, mainly requiring us to install a separate server software such as vsftpd.

An extra bonus you should also check out our guide on how to set up a mounted USB drive, so you have plenty of room for files and more. This tweak will help save you space on your SD card.

So, let’s get started with learning how to set up FTP and SFTP on the Raspberry Pi.

Equipment

You will need the following equipment to complete this tutorial on setting up an FTP server on the Raspberry Pi.

Raspberry Pi

Power Supply

Micro SD Card (8gb+ Recommended)

Ethernet Cable (Recommended) or WiFi Dongle

Raspberry Pi Case (Optional)

In this FTP server tutorial we are using Raspberry Pi OS.

If you don’t have it installed then check out my guide on installing NOOBS Raspberry Pi. (It’s the easiest way to get Raspbian onto your SD Card for a beginner)

Video

Be sure to check out our video below for a visual guide on setting up FTP on your Raspberry Pi.

Alternatively we have a full written guide just below this video.

If you like what you see, then please make sure you subscribe or follow us on social media, so you stay up to date on our latest stuff.

Adblock blocking the video? Support us by subscribing to our ad-free service.

Setting up your Raspberry Pi for SFTP

Setting up your Raspberry Pi to be able to use SFTP is a very straightforward process and requires no additional software to be installed.

All we need to do is make sure that SSH is enabled by using the Raspi-config tool.

If you have already got SSH enabled, then you can skip ahead to the “How to Connect” section further down in this tutorial.

1. On the Raspberry Pi open up the terminal.

You can find this in the task bar at the top of the screen by default.

Alternatively you can press CTRL + ALT + T to open the terminal.

2. Within the terminal you will need to enter the following command.

This command will launch the raspi-config tool that we can use to enable SFTP on your Raspberry Pi.

sudo raspi-config

3. Within this tool you need to go to the “5 Interfacing Options” option.

You can navigate through the menu by using the ARROW keys to move up and down, then the ENTER key to select an option.

SFTP On Raspberry Pi - Raspi-Config Main Menu

4. On the next screen find and select the “P2 SSH” option.

This option is what will allow us to enable the SSH service on our Raspberry Pi.

Enabling SSH On the Raspberry Pi for SFTP Menu

5. To actually enable SSH on your device, you need to select the <Yes> option.

Enabling SSH will give us access to the SFTP functionality of the protocol.

Raspi-Config Enable SSH for SFTP on Raspberry Pi

6. At this point you have now successfully enabled SSH on your Raspberry Pi.

You can quit out of this tool now by pressing the ESC key.

Successfully Enabled FTP Server on Raspberry Pi

7. You can now proceed down to our “How to Connect to the FTP Server” section of this tutorial.

This section will walk you through connecting to your Raspberry Pi over the SFTP protocol.

You will be able to connect to the Raspberry Pi over SFTP by using port 22.

Setting up an FTP Server on the Raspberry Pi

In this section we are going to be walking you through the process of getting plain FTP working on your device.

To make all of this work we will be making use of a piece of software called vsftpd.

We chose to use vsftpd as it is regarded as one of the most secure and fastest FTP servers that you can run on the Raspberry Pi.

1. Before we proceed let us ensure that our Raspberry Pi OS is running the latest available packages.

To update all packages on the device you will need to run the following two commands on the terminal.

sudo apt update
sudo apt full-upgrade

Updating all packages ensures that we shouldn’t run in to any weird issues when installing vsftpd on to our Raspberry Pi.

2. Once the update process has completed we can now install the software we require.

Install vsftpd to your Raspberry Pi by using the command below.

sudo apt install vsftpd

3. Before we can connect to our new Raspberry Pi FTP server we need to modify some settings.

Let us begin modifying the vsftpd configuration file by using the nano text editor with the following command.

sudo nano /etc/vsftpd.conf

4. Within this file you will need to add or uncomment (Remove the #) the following settings.

If you want to find options faster you can make use of the CTRL + W shortcut to search the file.

anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
chroot_local_user=YES
user_sub_token=$USER
local_root=/home/$USER/FTP

Using these options we set it so that the user logging in is locked in to there directory.

In our case we are using “local_root” option so that the user will be locked to their home directory within a folder called “FTP“.

5. Once you are done press CTRL + X and then Yto save and exit.

6. Now we need to create the FTP directory so we can transfer files.

The root directory is not allowed to have write permissions so we will need a subfolder called files.

Replace <user> with the relevant user

Make sure that you replace “<user>” with the relevant user. For example, the default user on Raspberry Pi OS is “pi“.

mkdir -p /home/<user>/FTP/files

By using the -p argument we are telling mkdir that it needs to create the entire path tree.

So in our case it will create both our “FTP” and “files” directories.

7. With the directory added we need to modify its permissions so that we remove the write permission from the FTP directory.

Doing this will ensure no one can add files in to the FTP directory that they shouldn’t be.

Again make sure that you replace “<user>” with the user that you are using.

chmod a-w /home/<user>/FTP

8. For our new settings to take effect we need to restart the vsftpd daemon on the Raspberry Pi.

We can now restart the service by using the following command.

sudo service vsftpd restart

9. With the FTP server set up and running on our Raspberry Pi you can now connect to it.

You should now be able to connect to the FTP server on your Raspberry Pi over Port 21.

How to Connect to your Raspberry Pi’s FTP Server

You can now connect to your Raspberry Pi by using either FTP or SFTP, depending on which protocol you decided to go with.

For this tutorial we are going to by using the FileZilla FTP client as it has support for both FTP and SFTP while also working on numerous operating systems.

There are plenty more FTP clients that you can check out. Another solid alternative is WinSCP, however, that is Windows only.

Any FTP client should be able to connect to the server with little to no issues.

1. On your PC head over to the FileZilla download page and download the relevant client for your operating system.

2. Upon opening up the FileZilla software you will be able to login to your FTP server.

1 – First you need to enter in the IP address of your Raspberry Pi. (1.)

2 – Next, you need to enter the username for the user we are trying to connect with. If you are sticking with the default user this will be “pi” (2.).

3 – After that, you will need to enter the password for that user. Again if you are using the default user you will need to use the password “raspberry” (3.).

4 – The final option that needs filling out is the port. The port differs slightly depending if you are using SFTP or FTP on your Raspberry Pi.

If you are using plain FTP enter the port 21 in to the textbox. Alternatively if you are using SFTP, you will need to enter the port 22. (4.)

Connecting to Raspberry Pi FTP Server using FileZilla Details

3. At this point, you should enter in all the connection details for your Raspberry Pi FTP server.

Once you are happy everything is correct, connect by clicking the Quickconnect button.

Using FileZillas QuickConnect Function

4. If everything is working as it should be you should now be successfully connected over FTP or SFTP.

5. To make sure everything is working you should now test the connection by transferring a couple of files.

External Access

If you want to access FTP outside your internal network, then please follow my guide on setting up Raspberry Pi port forwarding.

The port you want to forward for SFTP is 22.

If you’re going to enable plain FTP, then you will need to forward port 21 as well.

I would suggest having a different external port then to the standard internal port to make it harder for someone to try and gain access.

Troubleshooting

Permission denied: This means you’re trying copy files to or from a place where your current user doesn’t have the correct permissions.

To fix this issue, you will need to change the permission of that particular location to allow your current user or login with a different user.

You might find that FTP isn’t enough for what you require. If you’re looking for something a little more advanced, then the network attached storage tutorial might take your fancy.

Using the tutorial you can set your Pi up to act as a NAS by using protocols such as SAMBA.

I hope this guide has provided you with enough information to get your Raspberry Pi up and running with either FTP or SFTP.

If you do come across some issues or you notice a mistake then please don’t hesitate to leave a comment below.

9 Comments

  1. Avatar for Vincenzo Frezza
    Vincenzo Frezza on

    Suggestions:

    In step 3 change:

    local_root=/home/$USER/ftp

    in

    local_root=/home/$USER/FTP

    In step 5 change:

    chmod a-w /home//ftp

    in

    chmod a-w /home//FTP

    Thank you for the precious tutorial.

    Vincenzo Frezza

    1. Avatar for Gus
      Gus on
      Editor

      Hi Vincenzo,

      Thank you for pointing out those issues. We have corrected the tutorial!

      Cheers,
      Gus

  2. Avatar for Greg
    Greg on

    Since this is an FTP server, is there a way to add users (and their respective passwords) just for vsftp? I know i used fillzilla server for windows and I could add users, and also set which profile each user had access to, where the profiles were basically just groups of folders. I’m currently trying to move my ftp server from my windows machine to my pi. Thanks!

    1. Avatar for mike
      mike on

      If I understand your question, you should be able to do this by adding groups in linux. Just create a group that you want to only use vsftp and give that group exclusive access.

  3. Avatar for Siamak
    Siamak on

    Hi everyone,

    The tutorial is indeed very interesting for those who don’t have VPN servers.

    I have set-up an OpenVPN server and by using WinSCP the file transfer takes place very smoothly from any where in the world.

  4. Avatar for Daniel
    Daniel on

    Thomas, use this command:

    sudo chgrp www-data /var/www 
    sudo chmod 777 /var/www 
    sudo chmod g+s /var/www 
    sudo usermod -a -G pi 
    sudo chown -R pi /var/www
    1. Avatar for Don
      Don on

      Daniel, 4th line must be:
      sudo usermod -a -G www-data pi

  5. Avatar for Thomas
    Thomas on

    how can I change the permission of the var/www/html map so I can copy files into it? I get the message that I don’t have the permission.

  6. Avatar for RichardL
    RichardL on

    This is almost the first thing I’ve done on RPi, and it worked for plain ftp, but in points 3 and I think all the FTP/ftp folder name should be the same case.

Leave a Reply

Your email address will not be published. Required fields are marked *