Set up an FTP server with Docker
FTP (File Transfer Protocol) is a data transfer protocol for transferring files (e.g. text files, pictures or videos) via an IP network. It is an old and solid protocol. It exists since 1971.
FTP servers use this protocol, which is based on TCP. A client can upload or download data to the FTP server. Communication takes place according to the client-server principle. The default port of an FTP server is 21.
In this article, we will set up an FTP server with Docker. We will also connect the server to the Netatmo Doorbell so that the Netatmo software stores the video data on our server.
The steps are the following:
- Technical requirements
- FTP - Types of connection
- Netatmo Doorbell
- Setup an FTP server with Docker
- IT Security
- Connect the FTP server with Netatmo Doorbell
- Conclusion
Technical requirements
You will need the following prerequisites:
- The latest version of Docker must be installed on your machine. If you do not have it installed yet, please follow the instructions.
- The latest version of Docker Compose must be installed on your machine. Please follow the instructions.
- Access to a bash (macOS, Linux or Windows).
FTP — Types of connection
The following information is based on FTP — File Transfer Protocol. FTP establishes two logical connections between the client and the server. One connection is the command channel via TCP port 21. This channel only transmits FTP commands. FTP transmits the data in a second connection via port 20. First the control channel is established and then the data channel. There are two modes.
FTP Active Mode: The FTP client contacts the FTP server via port 21 and transfers the port number for data transfer (e.g. port 20). The FTP server then establishes the connection to the FTP client via this port.
FTP Passive Mode: First, the FTP client and server establish a new connection via port 21. Then the FTP server transmits a port number to the FTP client. The data connection uses this port. The FTP client contacts the server on this port.
Netatmo Doorbell
The Netatmo Smart Video Doorbell is a doorbell with camera function. You can integrate the Doorbell into your home automation system. It also supports Apple HomeKit. You can save your recordings on an FTP server. The following photo shows the doorbell.
In the following section, we set up an FTP server to store the video recordings of the doorbell. The FTP server is also suitable for the Netatmo Smart Outdoor Camera.
Setup an FTP server with Docker
First, you should check that you have Docker installed correctly. Enter the following command in your terminal:
docker --version
# Example output: $ Docker version 20.10.21
If the installation is correct, the Docker version is output. You can check the same for your Docker Compose installation.
docker-compose --version
# Example output: $ Docker Compose version v2.12.2
Yeah. Everything is ok. 😀 Now we can look at the docker-compose file and the .env file.
First, create a folder with the name FTP. Then create a file called .env in the FTP folder. Fill the .env file with the following content:
FTP_USERNAME=ftpuser
FTP_PASSWORD=testpassword
In the next step, you create a shared folder. The FTP server saves your files in this folder. Then create a file docker-compose.yml. Add the following content to this file:
version: '3.7'
services:
ftp:
container_name: ftp-server
image: garethflowers/ftp-server
environment:
- FTP_USER=${FTP_USERNAME}
- FTP_PASS=${FTP_PASSWORD}
restart: always
ports:
- '20-21:20-21/tcp'
- '40000-40009:40000-40009/tcp' # passive mode
volumes:
- ./shared:/home/${FTP_USERNAME}/shared
Under services we see our service ftp. The container has the name ftp-server. Furthermore, we use the Docker image garethflowers/ftp-server from DockerHub. You can also have a look at the associated GitHub repo.
We also set the two environment variables FTP_USER (for the user name) and FTP_PASS (for the password). In addition, the container keeps trying to restart. For the port, we allow ports 40000–40009. The FTP server can use passive mode. That is especially important with Netatmo devices, as they only work with FTP servers in passive mode. Netatmo writes the following on its website:
Your FTP server needs to be configured in the “passive” mode.
Currently, SFTP and FTPS are not supported by our Cameras
So we cannot use a secure variant (e.g. FTPS or SFTP) with Netatmo devices. In the next section, we look at IT security, because it is an important aspect. You should always be aware of the strengths and weaknesses of the systems you want to use.
IT Security
There are two secure variants of FTP: FTPS and SFTP.
FTPS stands for FTP over SSL. The connection is secured via Transport Layer Security (TLS). That means that the data exchange is encrypted.
SFTP stands for SSH File Transfer Protocol. SFTP uses the Secure Shell (ssh) for the secure data transfer of files. The connection is also encrypted. We have also written an article about SFTP.
IMPORTANT!!! The FTP server does not have encrypted data transfer.
Connect the FTP server with Netatmo Doorbell
First, start your FTP server with the following command:
docker compose up -d
The flag -d means that the container is running as a daemon. In this mode, the terminal does not output any logs.
Open your Netatmo Home + Security app and navigate to the settings. There you click on Cloud storage. Then click on FTP settings. And then click on Netatmo Doorbell. Next, go to the Advanced settings. There you can enter the IP address, the port, the username and the password. You can specify the folder where the FTP server stores your data. Ready. From now on, the doorbell stores the videos on your FTP server.
Have fun with it!
Conclusion
The article has introduced the basics of FTP. In addition, an FTP server with Docker was set up and started. FTP transfers data unencrypted. The alternatives are FTPS and SFTP. Finally, we connected the FTP server to the Netatmo doorbell.
💡 Do you enjoy our content and want to read super-detailed articles about data science topics? If so, be sure to check out our premium offer!
Leave a comment