Pure-ftp of FTP

Source: Internet
Author: User

Basic requirements: To achieve the FTP account expiration automatic shutdown, delay, limit, speed limit operation,


System Setup

System:centos6.4

Software:pureftpd+mysql

Software version: pure-ftpd-1.0.36

Installation:

#yum-y install httpd mysql-devel mysql-server gcc

#tar XVF pure-ftpd-1.0.36.tar.gz

#cd pure-ftpd-1.0.36

#./configure--prefix=/usr/local/pure-ftpd/--with-everything--with-altlog--with-puredb--with-ftpwho--with-mysql --with-throttling--with-ratios--with-quotas--with-virtualhosts--with-virtualchroot--with-sysquotas-- with-cookie--with-rfc2640--with-bonjour--with-welcomemsg--with-language=simplified-chinese--with-uploadscript

#make &make Install

#mkdir/usr/local/pure-ftpd/etc/

#cpconfiguration-file/pure-ftpd.conf/usr/local/pure-ftpd/etc/

#cpconfiguration-file/pure-config.pl/usr/local/pure-ftpd/sbin/

#cppureftpd-mysql.conf/usr/local/pure-ftpd/etc/

#chmod755/usr/local/pure-ftpd/sbin/pure-config.pl

Part

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/56/AE/wKiom1SKkc3jvvuaAAHo-vYd_oA899.jpg "title=" 1.png " alt= "Wkiom1skkc3jvvuaaaho-vyd_oa899.jpg"/>

#ln-S/usr/local/pure-ftpd/bin/*/usr/local/bin/

#ln-S/usr/local/pure-ftpd/sbin/*/usr/local/sbin/

#ln-S/usr/local/pure-ftpd/share/man/man8/*/usr/local/share/man/man8/

#groupadd-G 10000 hzftp

#useradd-u 10000-g 10000-d/var/ftp-s/sbin/nologin hzftp

#passwd hzftp (123456)

#cp/etc/skel/.b*/mnt/hzftpdata/Note:/mnt/hzftpdata is the directory where the FTP account is stored

#vi/usr/local/pure-ftpd/etc/pure-ftpd.conf

Verboselog Yes

Noanonymous Yes

Mysqlconfigfile/usr/local/pure-ftpd/etc/pureftpd-mysql.conf

PassivePortRange 30000 50000

Minuid 10000

Altlog Clf:/var/log/pureftpd.log

Altlog Stats:/var/log/pureftpd.log

Altlog W3c:/var/log/pureftpd.log

Reatehomedir Yes

Quota 1000:10


Create a database

#mysql

CreateDatabase pureftpd;

Grantselect on pureftpd.* to [e-mail protected] identified by ' 456789 ';

Flushprivileges;

CreateTable if not exists ' users ' (' user ' varchar (+) NOT null default ' ', ' password ' varchar (+) ' NOT null default ' ', ' star Tdate ' date not null, ' enddate ' date notnull, ' uid ' int (one) not null, ' gid ' int (one) not null, ' dir ' varchar (+) Notnull Default ' ', ' quotafiles ' int (ten) NOT null default ' 10000 ', ' quotasize ' int (ten) NOT null default ' "", ' ulbandwidth ' int (1 0) Not NULL, ' dlbandwidth ' int (ten) not null, ' ipaddress ' varchar (all) NOT null default ' * ', ' comment ' tinytext, ' status ' enum (' 0 ', ' 1 ') NOT NULL The default ' 1 ', ' ulratio ' smallint (5) NOT null default ' 1 ', ' dlratio ' smallint (5) is not null default ' 1 ', ' EMA Il ' varchar ' is not NULL default ', PRIMARY key (' user '), unique key ' user ' (' user ') Engine=innodb default Charset=utf8;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/56/AF/wKiom1SKnX3B9KnoAAJqx35bUp8503.jpg "title=" 1.png " alt= "Wkiom1sknx3b9knoaajqx35bup8503.jpg"/>

The actual use of the account found in the closed function is not ideal, so consider using two tables users and closedftp.

Store active accounts and closed accounts separately Information

CREATE TABLE closedftp select * from users;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/56/AF/wKiom1SKnpmhAIodAABAER_5r8c206.jpg "title=" Untitled. png "alt=" wkiom1sknpmhaiodaabaer_5r8c206.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/56/AF/wKiom1SKnsix1csNAADtUittD6g242.jpg "title=" Untitled. png "alt=" wkiom1sknsix1csnaadtuittd6g242.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/56/AD/wKioL1SKn56x_w0MAAGUS_2uQMY978.jpg "title=" Untitled. png "alt=" wkiol1skn56x_w0maagus_2uqmy978.jpg "/>

Modify Database Configuration

VI pureftpd-mysql.conf

Mysqlsocket/var/lib/mysql/mysql.sock

Mysqluser hzftp

Mysqlpassword 456789

Mysqlcrypt MD5

Start MySQL and FTP services

#service mysqld Start

#/usr/local/pure-ftpd/sbin/pure-config.pl/usr/local/pure-ftpd/etc/pure-ftpd.conf

At this point the FTP set up, through the operation of MySQL to achieve user management is more troublesome

Here I am using script to implement

The contents are as follows:


More ftp-manage.sh

#/bin/bash

Hostnme= "127.0.0.1"

Port= "3306"

Username= "Hzftp"

Password= "456789"

Dbname= "PUREFTPD"

Tablename= "Users"

tablename1= "Closedftp"

#closeday = (date +%y-%m-%d)

#shutday = (date +%y-%m-%d)

echo "Select operation;"

echo "1): Add Account"

echo "2): Change Password"

echo "3): Disable Account"

echo "4): Auto Disable"

echo "5): Closed account Extension"

echo "6): in-Use account extension"

echo "7): View account Information"

echo "Please select operation"

Read operation

Case ' $operation ' in


1)

Read-p "Input FTP name:" Name

Read-p "Input ftp password:" Pass

Read-p "Input Closeday: (formatted as 0000-00-00)" Closeday

Sql= "select Max (UID) from users limit 1"

echo "User ID is generally incremented, the current ID is used to"

sql_max= "select Max (UID) from users limit 1"

Echo & (Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql_max}")

Read-p "Input user ID:" UD

Read-p "Input quota size:" Qsize

userhome=/mnt/hzftpdata/$name

Echo Information Confirmation

echo User name: "$name", Password: "$pass", Close date: "$closeday", User id: "$ud", Limit: "$qsize", Path: "$userhome"

echo "Ctrl + C" Cancel operation

Sleep 10

Sql= "INSERT into users values (' $name ', ' $pass ', ' $ (date +%y-%m-%d) ', ' $closeday ', ' $ud ', ' 10000 ', ' $userhome ', ' 10000 ', ' $ Q

Size ', ' 300 ', ' 300 ', ', ', ' 1 ', ' 1 ', ' 1 ', ') '

sql1= "Select User,password,startdate,enddate,uid,gid,dir from Users where user= ' $name '"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql}"

echo "Message confirmed:"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${SQL1}"

;;

2)

Read-p "input name:" Name

Read-p "Input pass:" Pass

Sql= "Update users set password= ' $pass ' where user= ' $name '"

Sql2= "Select User,password,dir,enddate from Users where user= ' $name '"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql}"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql2}"

;;

3)

Read-p "input name:" Name

Sql= "Update users set status= ' 0 ' where user= ' $name '"

sql2= "INSERT INTO CLOSEDFTP SELECT * from users where status= ' 0 ' and user= ' $name '"

sql3= "Delete from users where user= ' $name '"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql}"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql2}"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql3}"

;;

4)

Sql= "Update users set status= ' 0 ' where enddate<= ' $ (date +%y-%m-%d) '"

sql2= "INSERT INTO CLOSEDFTP SELECT * from users where enddate<= ' $ (date +%y-%m-%d) '"

sql3= "Delete from users where enddate<= ' $ (date +%y-%m-%d) '"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql}"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql2}"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql3}"

;;

5)

Read-p "Please enter the account to be deferred:" Name

Read-p "deferred time (format 0000-00-00):" Closeday

sql= "Update closedftp set enddate= ' $closeday ', status= ' 1 ' where user= ' $name '"

Sql2= "INSERT into the users select * from closedftp where user= ' $name '"

sql3= "Delete from closedftp where user= ' $name '"

sql4= "Select User,password,dir,enddate from Users where user= ' $name '"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql}"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql2}"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql3}"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql4}"

;;

6)

Read-p "Please enter the account to be deferred:" Name

Read-p "deferred time (format 0000-00-00):" Closeday

Sql= "Update users set enddate= ' $closeday ' where user= ' $name '"

Sql2= "Select User,dir,enddate from Users where user= ' $name '"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql}"

echo "Information changed"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql2}"

;;

7)

Read-p "input name:" Name

Sql= "Select User,password,dir,startdate,enddate from Users where user= ' $name '"

Mysql-h ${hostname}-p${port}-u${username}-p${password} ${dbname}-E "${sql}"

;;

*) echo "Error,please select 1,2,3,or 4:"

;;

Esac



Pure-ftp of FTP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.