This project provides a simple yet powerful Python script that creates an FTP/FTPS server. Its primary purpose is to act as a gateway, allowing any standard FTP client to connect and interact with a specified local or network-mounted drive on the host machine.
This is useful for legacy devices (like security NVRs) that can only back up to an FTP server, allowing them to save files directly to a modern storage solution like a network drive.
- FTP and FTPS: Supports standard unencrypted FTP and secure FTP over SSL/TLS (FTPS) with both explicit and implicit modes.
- Flexible Authentication: Allows for a single authenticated user, anonymous access, or both.
- Direct File Access: Files are read from and written directly to the target directory. No temporary storage is used.
- Configurable: All major settings (directory, host, port, credentials) can be configured via command-line arguments.
- Cross-Platform: Runs on any operating system with Python and a network connection.
- Python 3.6+
pyftpdliblibrary- For FTPS Support:
pyOpenSSLis required to enable the TLS/SSL features.
-
Clone this repository or download the
ftp_server.pyscript. -
Install the required Python libraries.
For standard FTP:
pip install pyftpdlib
For secure FTPS: The
pyOpenSSLlibrary is required for FTPS functionality. Install it first, then reinstallpyftpdlibto ensure it builds with the necessary TLS/SSL support.pip install pyOpenSSL pip install --upgrade --force-reinstall pyftpdlib
Run the server from your terminal, providing the path to the directory you want to serve.
--drive(Required): The absolute path to the network drive or directory to serve.--host: The host IP address to bind to. (Default:0.0.0.0, listens on all interfaces)--port: The port to listen on. (Default:21for FTP/Explicit FTPS,990for Implicit FTPS)--user: Username for authenticated access.--password: Password for authenticated access.--allow-anonymous: If present, allows anonymous read and write access.--ftps-mode: Enables FTPS and sets the mode. Can beexplicitorimplicit. If a certfile is provided without this argument, it defaults toexplicit.--certfile: Path to the SSL certificate file (required for FTPS).--keyfile: Path to the SSL private key file (required for FTPS).
1. Basic FTP with a User
Serve the Z:\backups directory on the default port 21 for myuser.
python ftp_server.py --drive "Z:\backups" --user myuser --password mysecretpassword2. FTP with Anonymous Access
Serve the C:\public directory, allowing anonymous users to connect, read, and write files.
python ftp_server.py --drive "C:\public" --allow-anonymous3. Secure FTPS Server (Explicit Mode)
Serve the Z:\secure-storage directory using Explicit FTPS on port 21. The client must initiate the TLS handshake.
python ftp_server.py --drive "Z:\secure-storage" --user myuser --password mysecretpassword --ftps-mode explicit --certfile "cert.pem" --keyfile "key.pem"Note: If you provide a certfile and keyfile without the --ftps-mode argument, the server will default to explicit mode.
4. Secure FTPS Server (Implicit Mode)
Serve the Z:\secure-storage directory using Implicit FTPS. It is recommended to use the standard port 990 for this mode.
python ftp_server.py --drive "Z:\secure-storage" --port 990 --user myuser --password mysecretpassword --ftps-mode implicit --certfile "cert.pem" --keyfile "key.pem"For testing or internal use, you can generate a self-signed SSL certificate using openssl.
openssl req -new -x509 -nodes -out cert.pem -keyout key.pem -days 365This command will prompt you for some information and generate cert.pem and key.pem files in your current directory, valid for 365 days. You can then use these files with the FTPS arguments.