Quick and easy FTP server install on a Raspberry Pi
For this setup, i’m using Ubuntu 16.04 running on a Raspberry Pi 3. The instructions should work correctly in Debian and Raspbian too – in fact, you will probably have luck using these instructions on any Linux operating system, Raspberry Pi or not.
Note: FTP is not a secure protocol, I would recommend using SFTP for production environments.
-
Login to SSH with
root
or a user which has sudo permissions. The default Raspberry Pipi
user should be okay. -
Update packages:
sudo apt-get update
-
Create a new user, used only for FTP connections:
sudo adduser ftp-user
Enter a password of your choice.
-
Create a folder in
/root
. This is where the USB HDD will be permanently mounted.sudo mkdir /usb-hdd-storage
-
Mount the USB HDD to this folder, this assumes your USB HDD is formatted as NTFS. Firstly check to see the partitions available on the USB HDD drive:
sudo blkid
This should output the USB HDD’s label, keep a note of this.
-
Check the boot name of the USB HDD’s partition:
sudo fdisk -l
-
Now we know where our drive is, we need to mount it to the
/usb-hdd-storage
folder we created previously:sudo mount /dev/sdaX /usb-hdd-storage
You may need to replace
X
with your drive ID. This can be found from the ‘blkid’ command.You’ll also have to set permissions to ensure the drive can be accessed properly:
sudo chmod 775 /usb-hdd-storage
-
To make the USB HDD mount permanently, edit the ‘fstab’ file:
sudo nano /etc/fstab
Add this line to the bottom of the file:
/dev/sdaX /usb-hdd-storage ntfs defaults 0 0
As before, replace
X
with your drive ID.Note: If you need to unmount the drive, run:
sudo umount /usb-hdd-storage
-
Create a folder in the ‘ftp-user’ home directory, this will be used in the next step to ‘bind’ to the folder we created in
/root/usb-hdd-storage
:sudo mkdir /home/ftp-user/usb-hdd-storage
-
Perform a bind to where the USB HDD is mounted. Edit the ‘fstab’ file so this bind is permanent:
sudo nano /etc/fstab
Add this line to the bottom of the file, it should be below the line which was added in the previous step:
/usb-hdd-storage /home/ftp-user/usb-hdd-storage none bind 0 0
-
Now change the ownership of this folder to the ‘ftp-user’ user:
sudo chown ftp-user:ftp-user /home/ftp-user/usb-hdd-storage
-
Install proFTPd:
sudo apt install proftpd
Choose to run proFTPd as
standalone
. -
Now edit the proFTPd configuration file:
sudo nano /etc/proftpd/proftpd.conf
Change the
TimeoutIdle
value to60
. This is 60 seconds.And uncomment
DefaultRoot
so users are ‘jailed’ to their home directories, they will still be able to access files on the USB HDD because of the ‘binded’ folder we created. -
Reload the proFTPd service to pick-up the changes made in the configuration file:
sudo service proftpd reload
-
You can now reboot the operating system and test the connection in a FTP program, such as FileZilla.
sudo shutdown -r now
Or to shutdown, run:
sudo shutdown -h now
Comments
Joe G Rodriguez
10/24/2018
This is the First Raspberry Pi 3 FTP Server that loaded with no Errors. I really Appreciate the USB Hard Drive Load addition.
I just hope I can Figure out how to Send Data from a Security Camera to this Server???
Thanks
Joe
Joe G Rodriguez
I did everything as stated on this page. When I logged in FileZilla I Typed in My IP 192.168.1.146 (I did not anything in front of the IP) FileZilla Put in (sftp://192.168.1.146) User Name: Pi and my: Password. I left Port: Blank.
I get a listing but I can’t find the HDD???
All the Folders have ? marks in the Folders.
Can you help?
Ryan
Hi Joe, Did you change directory to the HDD mount point? In my case, the mountpoint was stored as ‘usb-hdd-storage’ within the ‘ftp-user’ home directory. Your setup might be different, but if you followed the tutorial exactly, you should be able to transfer files to the HDD in FileZilla by changing directory to this location: /home/ftp-user/usb-hdd-storage
Joe Rodriguez
Ryan thanks for the reply. I’m going to start all over again with a new Raspbian System. I just had Surgery so I lost a few Days and I’m not supposed to sit at the Computer very Long. But, I just have to try again. I will follow everything exactly as you have it. You have my email. I wish I could get yours so I can get this right.
For your information I’m trying to set the Raspberry Pi 3 with 1tb Western Digital Ultra up as an FTP Server for Security Camera.
Thanks
Joe
San Antonio, TX
Joe G Rodriguez
Ryan
I just reloaded everything as per your instructions. I’m using Filezilla on a Windows 10 64 Desktop. Everything looked like loaded right except for the New Version of ProFTPD does not ask for Standalone.
Now how do I login to Filezilla My address if 192.168.1.146 do I need anything infront of the IP? What do login with FTP-user or Pi or what? I guess my password is the one I used?
Thanks
Joe
Joe G Rodriguez
Ryan – I logged in to Filezilla with my IP and My Password.
Status: Connecting to 192.168.1.146:21…
Status: Connection established, waiting for welcome message…
Status: Insecure server, it does not support FTP over TLS.
Status: Logged in
Status: Retrieving directory listing…
Status: Directory listing of “/” successful
Status: Retrieving directory listing of “/usb-hdd-storage”…
Command: CWD /usb-hdd-storage
Response: 550 /usb-hdd-storage: No such file or directory
Error: Failed to retrieve directory listing
Status: Retrieving directory listing of “/usb-hdd-storage”…
Command: CWD /usb-hdd-storage
Response: 550 /usb-hdd-storage: No such file or directory
Error: Failed to retrieve directory listing
Status: Connection closed by server
Can you email me so I can fix this. You have my Email. I have screen captures of everything I did.
Thanks
Joe
Ryan
Hi Joe,
Looks like it is logging in properly, but seems the issue is with the USB HDD mountpoint. Have you created the ‘usb-hdd-storage’ in the root? If so, re-try the steps to mount your hard drive to this folder. If it’s still not working, then unfortunately i’m not sure. I tested this myself when I wrote the post on Raspberry Pi 3 and it worked perfectly.
Joe G Rodriguez
Ryan
I don’t know if this shows where the HD is mounted but let me know what to type to find out?
[email protected]:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 4.5G 24G 17% /
devtmpfs 460M 0 460M 0% /dev
tmpfs 464M 0 464M 0% /dev/shm
tmpfs 464M 13M 452M 3% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 464M 0 464M 0% /sys/fs/cgroup
/dev/mmcblk0p1 41M 22M 19M 54% /boot
/dev/sda1 932G 205M 932G 1% /usb-hdd-storage
tmpfs 93M 0 93M 0% /run/user/1000
Thanks
Joe
Ryan
Looks like your hard drive is mounted, I can see 900gb. Have you tried either the pi or FTP user for logins?
My Raspberry Pi – VIRTUAL DAN
[…] the most difficult, as there are a couple FTP packages supported by Raspian. But thanks to Ryan Fitton’s post I got it to […]
Douglas Luton
I keep getting the ECONNREFUSED error in filezilla, I double checked, the port is set to the correct port in SFTPD.conf, I can’t seem to figure out why it’s denying me.
Ryan
Hi Douglas,
Are you getting this error when trying to connect from inside your network to the Pi’s IP address? Or is this happening when connecting externally via your WAN address?
Sometimes Internet providers will block ports even if you have opened them on your router.
DOUGLAS G LUTON
inside I could connect, then I tried again from outside this morning and I was able to get in, I’m guessing Gremlins………
Thank you for the response.
Doug
How would I substitute SFTP for FTP?
Ryan
Hi Doug, This post is based on using FTP. If you want to use SFTP instead, you should be able to setup a new user, then connect to the server via it’s SSH port.
For more info on how to setup SFTP, checkout this article: https://www.techrepublic.com/article/how-to-set-up-an-sftp-server-on-linux/
perdicaro
Hi, how can i activate FTPS?
Ryan
Hello, This tutorial doesn’t go into those details. May I suggest to try this tutorial instead: https://www.tecmint.com/secure-ftp-server-using-ssl-tls-on-ubuntu/amp/
perdicaro
thnx for your fast answer but the procedure than you give me don’t work for raspberrypi 🙁
Ryan
Ah, i’m not sure then. Maybe best for you to see if your question has already been covered in the official RPi forum: https://www.raspberrypi.org/forums/ – they’re a friendly bunch 🙂
matt
If I want to mount 2 usb drives both to my ftp, is it as simple as adding a repeat of this line /dev/sdaX /usb-hdd-storage ntfs defaults 0 0 to fstab?
Ryan
Hi Matt, I was testing this last week with my own setup. Yes pretty much, however you would want to mount the disk as a child directory, e.g. /usb-hdd-storage/disk-01 and /usb-hdd-storage/disk-02
Then share /usb-hdd-storage/ in the vsftpd config file, and also make this the home directory of your user.
Dayverton dos Santos Marques
Goodnight !
I managed to perform all the steps and access the EXTERNAL HD directory, the problem is that I don’t have write permission. Can anybody help me?
Ryan
Hello, you should be able to fix your permissions by setting the user and folder permissions with ‘chown’, e.g. sudo chown ftp-user:ftp-user /your_directory_path_here/
Dayverton Marques
Ryan, thank you very much managed to resolve here.
Your tutorial was the best I found so far.
I used this tutorial to create an ftp server where captured images of a work are being stored to create a timelapse. The project went well thanks to the knowledge that was passed on by you.
Simply, thank you very much!
Post a Comment