Setup Raspberry Pi FTP server
If you run a web server like the “lighttpd” on a Raspberry Pi, then it makes sense to install an FTP server to remotely load files into the webserver directory. For this purpose, there are several FTP servers for Raspberry Pi. For example, ProFTP or vsftpd. However, an installation of these FTP servers is not necessarily necessary.
FTP is an old and insecure protocol for file transfer. There is really no reason to run an FTP server. If you really want to do file transfer, you should do it with SSH. Mostly, an SSH server is already set up for remote access. The dominated then the FTP protocol, which one can handle the file transfer over the secure SSH connection. This is safer and at the same time as comfortable as with an FTP server. Functionally identical.
- If necessary, install an FTP server on Raspberry Pi.
- Download an FTP client and install it on your client.
- Check the availability of the SSH server via SFTP over the local network.
- Set up the web server so that you can load files directly into the web server directory via FTP.
Solution without installing an FTP server
Many solutions are based on the installation of an FTP server, such as ProFTP or vsftpd. But that is not necessary. What many do not realize is that SSH supports FTP commands in the form of SFTP. If the remote access works via SSH, you do not have to do anything more than build an SFTP connection (port 22) to Raspberry Pi with an FTP client, such as Filezilla.
For the connection one needs the IP address of Raspberry Pi, as well as user name and password. After a successful connection via FTP client, you automatically end up in the user’s home directory.
So that you do not end up in the home directory of the user (for example “pi”), but in the directory of the web server, you have to create an extra user or even easier to make the user’s home directory to the web server directory.
To do this, you have to make a few changes in the web server configuration:
sudo nano /etc/lighttpd/lighttpd.conf
In the editor you change the following line (or similar):
server.document-root = "/var/www/html"
Here you enter the home directory of the user. For example “/ home / pi”.
Then save and exit with: Ctrl + O, Enter, Ctrl + X
Note: Incorrect permissions are often the problem if the files contained in the home directory exist but can not be retrieved through the web server. This can be corrected with the following commands:
sudo chown pi: www-data -R /home/pi
sudo chmod 775 /home/pi
Setup user for SFTP (FTP over SSH)
So that you do not end up in the home directory of the user (for example “pi”) but in the directory of the web server, you have to create a user whose home directory is the web server directory.
For this we set up a new user, for example “piftp”, which we only use for the SFTP connection (SSH + FTP). Of course, another username can be chosen. This must then be taken into account in the further setup.
sudo adduser piftp --no-create-home
Then we have to assign a password that applies globally, ie for local login and SSH login. When typing in the password no wildcards are displayed, so you type “blind”.
Then we assign the new user to the group “www-data”.
sudo usermod -G www-data piftp
Then we connect the web server directory with the new user. The important thing is that the directory should exist before.
sudo usermod -d /var/www/html/piftp
Then we have to set the rights for this user. We make him the owner and then set the rights for the web server directory.
sudo chown piftp: www-data -R /var/www/html
sudo chmod 775 -R /var/www/html
There is almost no reason to run a FTP server standalone. If you want to offer files publicly for download, you can do it more conveniently with a web server. Even if the protocol HTTP is not quite as efficient as FTP.
To manage remote servers folder and file based, an encrypted protocol like SSH is much better suited.
Raspberry Pi as a file server
Raspberry Pi is also suitable as a file server in some ways. So a kind of hard disk or data storage in the network. There are various possibilities of realization, which have all their advantages, but also disadvantages.