#!/bin/bash

#this is a script for add ftpusers

while : ;do

if [ -z $user ]; then

read -p "please enter your ftp username:" user

else

while : ;do

if [ $(echo $pw |wc -c) -le 12 ]; then

read -p "please enter your ftp password(请输入密码,12位以上的任意字符):" pw

else

sed -i '$a\'$user'\n'$pw'' /etc/vsftpd/vuser.txt

db_load -T -t hash -f /etc/vsftpd/vuser.txt /etc/vsftpd/vuser.db

touch /etc/vsftpd/user_dir/$user

while : ;do

if [ "$(echo $local_root | cut -c 1-9)" != "/data/www" ]; then

read -p "please enter ftp home directory(请输入全路径,以/data/www开头):" local_root

else

echo "local_root=$local_root" >> /etc/vsftpd/user_dir/$user

while : ;do

if [ "$permit" != "upload" -a "$permit" != "ro" -a "$permit" != "rw" ]; then

read -p "please enter ftp user permit(upload|ro|rw):" permit

else

if [ $permit = "upload" ]; then

sed -i '$a\anon_upload_enable=YES\nanon_mkdir_write_enable=YES' /etc/vsftpd/user_dir/$user

echo "the $user permit is $permit,thanks for use scripts"

fi

if [ $permit = "ro" ]; then

echo "the $user permit is $permit,thanks for use scripts"

fi

if [ $permit = "rw" ]; then

sed -i '$a\anon_upload_enable=YES\nanon_mkdir_write_enable=YES\nanon_other_write_enable=YES' /etc/vsftpd/user_dir/$user

echo "the $user permit is $permit,thanks for use scripts"

fi

exit

fi

done

fi

done

fi

done

fi

done