How to set up an FTP server on the Raspberry Pi

How to set up an FTP server on the Raspberry Pi

There are a lot of reasons that you might want a quick and easy way to transfer files between your Raspberry Pi and your computer. Maybe you’ve put together a RetroPie gaming emulator and want to transfer some ROMs, or maybe you have Raspbian installed and just want a few of your key files. Whatever the reason, it’s a good idea to learn how to set up an FTP server on the Raspberry Pi.

With FTP (File Transfer Protocol) or SFTP (SSH File Transfer Protocol, also known as Secure File Transfer Protocol), you can transfer files from your Raspberry Pi to your other computers and vice versa. It takes a bit of set-up, but once running, it’s a really effective way to move files back and forth.

For this tutorial, I’ll assume that you’re using Raspbian as your operating system. That makes accessing your Pi via FTP very easy. It also means that you don’t necessarily have to install any external software: Raspbian comes with a program called sftp-server from the OpenSSH suite. sftp-server is SFTP, of course, rather than FTP, and that’s a good thing. The old FTP protocol leaves both command and data channels unencrypted, which leaves your data vulnerable to exploits like the man-in-the-middle attack.

How to set up an FTP server on the Raspberry Pi

Step 1: Enable SSH

At first, we have to make sure that SSH (Secure Shell) is enabled. There are two ways to do this, and it doesn’t matter which one you use.

Using the GUI

Go to Preferences > Raspberry Pi Configuration and click on the “Interfaces” tab. There, select “SSH: Enabled.”

Using the GUI

Using Terminal

Open Terminal and enter this command:

sudo raspi-config

Then go to Advanced Options and select SSH. The config asks you, “Would you like the SSH server to be enabled?” Select “Yes.”

Using Terminal

Using Terminal

The SSH server is now enabled and you can quit the config by selecting “Finish.”

That’s all we needed to do to set up the server. But, of course, that’s only half the battle.

Step 2: Connect to the FTP server

You now have an FTP server running on your Raspberry Pi, but in order to connect to that FTP server, you need a FTP client on whatever device you’re using to connect.

If you’re using a Windows PC, head over to FileZilla’s download page and install their fantastic software.

Go ahead and open FileZilla. Enter the following information:

FileZilla settings

Host: Your public/private IP address. If you don’t know your public IP address, you can go to Google – or DuckDuckGo, the default search engine on Raspbian – and write “what is my IP address.” If you are only going to use the FTP connection from inside your home network, you can use your private IP address that you can determine with this command:

hostname –I

Username: Your Raspberry Pi username (default: pi)

Password: Your Raspberry Pi password (default: raspberry)

Port: 22

After pressing the Quickconnect button, you should see the contents of your Raspberry Pi home directory (the default home directory is /home/pi) on the right side of the FileZilla window.

That’s it! You’re now ready to access and move files to and from your Raspberry Pi remotely. Not too hard, right?

Troubleshooting

If you’re unable to connect to the FTP server and are greeted with something like:

Error: Connection timed out after 20 seconds of inactivity

Error: Could not connect to server

…you will need to make sure that you have set up port forwarding on your router. What is port forwarding? Well, that just means that you want your router to translate for you. One of the ports on your router has to correspond to that port 22 we set up, or else your server will be closed to outside access.

There’s one last thing to note here. Using sftp-server to set up your FTP server gives access to users with sufficient privileges. If you want to give limited users the power to transfer files and directories, too, you’ll have to get your hands a bit dirtier. The Raspberry Pi Foundation has a pretty good guide to that project.

3 Comments on "How to set up an FTP server on the Raspberry Pi"

  1. Why does this imply you are setting up FTP (non secure)? This is NOT the same.

  2. This is a good tutorial on setting up SFTP, which is completely unrelated to FTP. Change the title please.

Leave a comment

Your email address will not be published.


*