Virtual FTP accounts with Pure-FTPd and MySQL
By Rayed
Pure-FTPd is a FTP server with many features that enable you to host virtual accounts, these are the features that I loved and tested:
- You can put the user information in MySQL database, without having to create a real UNIX account for each user.
- It also have the feature of creating the user home directory when the user logging, so all you need to create a new user is to add it to the database.
- CallUploadScript this feature will make the server run a script whenever a new file is uploaded, I used this feature to scan the file for viruses as soon as the user upload the file. (I use ClamAV as my virus scanner)
Installation (FreeBSD)
# cd /usr/ports/ftp/pure-ftpd/
# make install
# vi /etc/rc.conf
:
pureftpd_enable="YES"
pureftpd_upload_enable="YES"
pureftpd_uploadscript="/path/to/pureftpd_uploadscript.sh"
:
Configuration Files
# cat pure-ftpd.conf
Daemonize yes
MySQLConfigFile /usr/local/etc/pureftpd-mysql.conf
CreateHomeDir yes
CallUploadScript yes
For MySQL setting we need aother file:
# cat pureftpd-mysql.conf
MYSQLSocket /tmp/mysql.sock
MYSQLUser my_user
MYSQLPassword my_password
MYSQLDatabase my_database
MYSQLCrypt md5
MYSQLGetPW SELECT password FROM my_table WHERE username="\L"
MYSQLDefaultUID 1001
MYSQLDefaultGID 1001
MYSQLGetDir SELECT CONCAT('/path/to/pureftpd/',username) FROM my_table WHERE username="\L"
MySQLGetQTAFS SELECT quota_files FROM my_table WHERE username="\L"
MySQLGetQTASZ SELECT quota_size FROM my_table WHERE username="\L"