Configure ClamAV to scan files uploaded via FTP (PureFTPd)

In this note I want to tell you how to configure the ClamAV antivirus to scan files that are uploaded to the server via PureFTPD.

The example is for Linux Ubuntu. For CentOS there won’t be much difference.

First install clamav, update it and run:

apt-get install clamav clamav-daemon clamav-data
freshclam
service clamav-daemon start

Next you need to allow scripts to be executed when uploading files in the PureFTPd settings:

echo yes > /etc/pure-ftpd/conf/CallUploadScript

Now we create the script itself:

/etc/pure-ftpd/clam-checker

Here is the content:

#!/bin/sh
/usr/bin/clamdscan --remove --quiet --no-summary "$1"

Making it executable:

chmod +x /etc/pure-ftpd/clam-checker

Now open the file /etc/default/pure-ftpd-common in your favorite editor. Find the UPLOADSCRIPT section in it and add the following line to it:

UPLOADSCRIPT=/etc/pure-ftpd/clam-checker

Restart PureFTPD and enjoy life:

/etc/init.d/pure-ftpd restart