Home > ftp, server > PureFTP + MySQL with pure-uploadscript functionallity

PureFTP + MySQL with pure-uploadscript functionallity

First lets install pureftpd using apt-get:

Install pureftpd with the MySQL backend:

apt-get install pure-ftpd-mysql

Since I like having different log files for different services I edit syslog.conf to separate ftp log files to specific one:

vi /etc/syslog.conf

Add these line at the end of the file:

ftp.* /var/log/ftp

Create the required file and restart sysklogd:

touch /var/log/ftp
/etc/init.d/sysklogd restart

Edit MySQL connection information for pureftpd user:

vi /etc/pure-ftpd/db/mysql.conf

Add or uncomment the following lines in the file. Don’t forget to change the user and password details.

MYSQLSocket      /var/run/mysqld/mysqld.sock
MYSQLUser       pure-ftpd
MYSQLPassword   pure-ftpd_pass
MYSQLDatabase   pureftpd
MYSQLCrypt      cleartext
MYSQLGetPW      SELECT Password FROM users WHERE User="\L"
MYSQLGetUID     SELECT Uid FROM users WHERE User="\L"
MYSQLGetGID     SELECT Gid FROM users WHERE User="\L"
MYSQLGetDir     SELECT Dir FROM users WHERE User="\L"
MySQLTransactions On

Some more configuration settings and pure-uploadscript setup:

echo no > /etc/pure-ftpd/conf/PAMAuthentication
echo yes > /etc/pure-ftpd/conf/CreateHomeDir
echo yes > /etc/pure-ftpd/conf/CallUploadScript
echo yes > /etc/pure-ftpd/conf/ChrootEveryone

Edit PurFtpd’s common settings:

vi /etc/default/pure-ftpd-common

Change / uncomment the following lines:

STANDALONE_OR_INETD=standalone
VIRTUALCHROOT=false
UPLOADSCRIPT=/path/to/pure-ftpd/uploadscript
UPLOADUID=0
UPLOADGID=0

Create MySQL users, apply permissions for the details set on /etc/pure-ftpd/db/mysql.conf . Also create users table for PureFtpd web admin:

CREATE DATABASE pureftpd;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO 'pure-ftpd'@'localhost' IDENTIFIED BY 'pure-ftpd_pass';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO 'pure-ftpd'@'localhost.localdomain' IDENTIFIED BY 'pure-ftpd_pass';
FLUSH PRIVILEGES;
CREATE TABLE `users` (
  `User` varchar(32) NOT NULL,
  `Password` varchar(32) character SET latin1 collate latin1_bin NOT NULL DEFAULT '',
  `Uid` int(11) NOT NULL DEFAULT '14',
  `Gid` int(11) NOT NULL DEFAULT '5',
  `Dir` varchar(128) NOT NULL DEFAULT '',
  `QuotaFiles` int(10) NOT NULL DEFAULT '500',
  `QuotaSize` int(10) NOT NULL DEFAULT '30',
  `ULBandwidth` int(10) NOT NULL DEFAULT '80',
  `DLBandwidth` int(10) NOT NULL DEFAULT '80',
  `Ipaddress` varchar(15) NOT NULL DEFAULT '*',
  `Comment` tinytext,
  `Status` enum('0','1') NOT NULL DEFAULT '1',
  `ULRatio` smallint(5) NOT NULL DEFAULT '1',
  `DLRatio` smallint(5) NOT NULL DEFAULT '1',
  PRIMARY KEY  (`User`),
  UNIQUE KEY `User` (`User`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Create uploadscript.sh referred on previous step:

#!/bin/bash
 
    # UPLOAD_SIZE  : the size of the file, in bytes.
    # UPLOAD_PERMS : the permissions, as an octal value.
    # UPLOAD_UID   : the uid of the owner.
    # UPLOAD_GID   : the group the file belongs to.
    # UPLOAD_USER  : the name of the owner.
    # UPLOAD_GROUP : the group name the file belongs to.
    # UPLOAD_VUSER : the full user name, or the virtual user name. (127 chars max)
 
# Do something useful

Install the PureFTPd user manager:

1. Download the user manager for PureFtpd from here
2. Uncompress the file to a web accessible directory:
3. Point your browser to the chosen directory and open the file install.php
4. Follow the installation steps

And you’re done!

http://blog.melimato.com/wp-content/plugins/sociofluid/images/digg_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/reddit_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/stumbleupon_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/delicious_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/technorati_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/google_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/myspace_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/facebook_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/yahoobuzz_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/twitter_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/meneame_24.png
Categories: ftp, server Tags: , , , ,
  1. Alan
    November 20th, 2009 at 15:44 | #1

    This is a very useful tutorial. could you add to it by describing how to configure uploadscript and how to write a script that will email a notification when a file is uploaded and how to make it work.
    Thanks

  1. No trackbacks yet.

Comment moderation is enabled. Your comment may take some time to appear.

Additional comments powered by BackType