A Python-based FTP client with integrated ClamAV anti-virus scanning. This tool ensures that all files are scanned for viruses by a ClamAV agent before they are uploaded to the FTP server.
It consists of two main components:
my_ftp.py: A custom FTP library, built from the ground up using Python's socket module, that handles the core protocol commands and data transfers.ftp_client.py: An interactive command-line FTP client.clamav_agent.py: A server agent that receives files from the FTP client, scans them using ClamAV, and reports the result.
Before you begin, ensure you have the following installed:
- Python 3: Make sure Python 3 is installed on your system.
- An FTP Server: You need a running FTP server that the client can connect to.
- ClamAV: The ClamAV anti-virus engine must be installed on the same machine where you intend to run the
clamav_agent.py.
You need a functional FTP server. Below are basic setup guides for common FTP server software on Linux and Windows.
vsftpd (Very Secure FTP Daemon) is a popular choice for Linux systems.
Set up tutorial VSFTPD setup
Below is a brief summary:
- Install vsftpd:
sudo apt update sudo apt install vsftpd
- Configure vsftpd:
- Open the configuration file:
sudo nano /etc/vsftpd.conf. - It's recommended to disable anonymous access and allow local users to log in. Ensure the following lines are set:
anonymous_enable=NO local_enable=YES write_enable=YES chroot_local_user=YES
- Open the configuration file:
- Create an FTP User (Optional): You can use an existing user or create a new one for FTP access.
- Restart the Service:
sudo systemctl restart vsftpd
- Check if the Service works
sudo systemctl status vsftpd
FileZilla provides a straightforward GUI-based FTP server for Windows.
- Download and Install: Get the FileZilla Server installer from the official website.
- Configure Users:
- Open the FileZilla Server interface.
- Go to Edit > Users.
- In the "Users" panel, click Add to create a new user and set a password.
- In the "Shared folders" panel, add the directories that this user can access and set their permissions (e.g., Read, Write, Delete).
The clamav_agent.py script requires clamdscan (on Linux) or clamscan.exe (on Windows) to be accessible.
- Install ClamAV:
sudo apt install clamav clamav-daemon
- Update Virus Definitions: Run
freshclamto download the latest virus signatures. This may require you to stop the daemon first.sudo systemctl stop clamav-freshclam sudo freshclam sudo systemctl start clamav-freshclam
- Check Path: The script expects
clamdscanto be at/usr/bin/clamdscan. You can verify this withwhich clamdscan. If it's different, you must update the path in theget_clamscan_path()function inclamav_agent.py.
- Install ClamAV: Download the official installer from the ClamAV website.
- Check Path: The script expects
clamscan.exeto be atC:\\Program Files\\ClamAV\\clamscan.exe. If you installed it in a different location, you must update the path in theget_clamscan_path()function inclamav_agent.py. - Update Virus Definitions: Run the "Virus Definition Update" tool that comes with the installation.
-
Clone the Repository:
git clone https://github.com/thetrucy/ftp-clamd cd ftp-clamd -
Start the ClamAV Agent: Open a terminal or command prompt and run the agent. This agent will listen for files to scan.
python clamav_agent.py
You should see the output:
[SERVER] ClamAV scanning agent listening for clients on port 12067.... -
Start the FTP Client: Open a second terminal or command prompt and run the client.
python ftp_client.py
You will be greeted with the client's welcome message and a command prompt:
🚀 FTP Client with ClamAV Integration 🚀 🧠 Type 'help' or '?' for available commands. 💡 Use 'open <host> <port> <username> <password>' to connect. ftp>
The client works like a standard command-line FTP program.
First, connect to your FTP server using the open command.
ftp> open <host> <port> <username> <password>
Example:
ftp> open 127.0.0.1 21 myuser mypassword
✅ 220 (vsFTPd 3.0.3)
✅ Successfully connected to 127.0.0.1.
📍 Current directory: /home/myuser
ftp:/home/myuser>
Here is a list of available commands, which can also be viewed by typing help in the client.
| No. | Command | Expected Output |
|---|---|---|
| 1 | ls |
Displays a list of files and folders in the server’s current directory. |
| 2 | cd <dir> |
Changes the current folder on the server and shows a success notification. |
| 3 | pwd |
Shows the current directory path on the server. |
| 4 | lcd <dir> |
Displays the current local directory and allows changing it. |
| 5 | mkdir <dir>, rmdir <dir> |
Creates or removes a folder on the server and shows a success notification. |
| 6 | delete <file> |
Deletes a file in the server’s current directory and shows a success notification. |
| 7 | rename <old> <new> |
Renames a file or folder on the server and shows a success notification. |
| 8 | get <remote_file>, recv <remote_file> |
Downloads a file from the server to the local machine, with a progress bar and notifications. |
| 9 | put <local_file> |
Uploads a file from the local machine to the server after ClamAV scanning, with a progress bar and notifications. |
| 10 | mput |
Uploads multiple files, scanning each one and asking for confirmation if prompts are enabled. |
| 11 | mget <remote_dir> |
Downloads multiple files from the server, scanning each before download, and asks for confirmation if prompts are enabled. |
| 12 | prompt |
Toggles confirmation prompts for each file during put or get operations. |
| 13 | ascii, binary |
Switches the file transfer mode between ASCII (text) and binary (files). |
| 14 | status |
Displays current connection status, transfer mode, and ClamAV agent configuration. |
| 15 | passive <on/off> |
Toggles passive mode for FTP connections and shows a status message. |
| 16 | open <host> <port> <username> <password> |
Connects to the FTP server and shows success or failure notification. |
| 17 | close |
Disconnects from the server and sends a goodbye message. |
| 18 | quit, bye |
Exits the client, disconnects from the server, and sends a goodbye message. |
| 19 | help, ? |
Displays the list of available commands. |
| 20 | set_clamav_agent |
Allows configuring the ClamAV agent’s host and port. |