yum -y install vsftpd


mkdir /etc/vsftpd/vuser_conf


cat /etc/vsftpd/vsftpd.conf

anonymous_enable=NO

local_enable=YES

write_enable=YES

local_umask=022

dirmessage_enable=YES

xferlog_enable=YES

connect_from_port_20=YES

xferlog_file=/var/log/xferlog

xferlog_std_format=YES

ascii_upload_enable=YES

ascii_download_enable=YES

chroot_list_enable=YES

listen=YES

pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES

guest_enable=YES

guest_username=ftp

user_config_dir=/etc/vsftpd/vuser_conf

dual_log_enable=YES

vsftpd_log_file=/var/log/vsftpd.log

pasv_enable=YES

pasv_min_port=5000

pasv_max_port=6000

pasv_promiscuous=NO


cat /etc/vsftpd/vuser_passwd.txt

liuly  //用户名

1234567   //密码


db_load –T –t hash –f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db


cat /etc/pam.d/vsftpd 

#session    optional     pam_keyinit.so    force revoke

#auth       requiredpam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed

#auth       requiredpam_shells.so

#auth       includepassword-auth

#account    includepassword-auth

#session    required     pam_loginuid.so

#session    includepassword-auth

auth required pam_userdb.so db=/etc/vsftpd/vuser_passwd

account required pam_userdb.so db=/etc/vsftpd/vuser_passwd


cat /etc/vsftpd/vuser_conf/liuly

local_root=/data/liuly

write_enable=YES

anon_umask=022

anon_world_readable_only=NO

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_other_write_enable=YES


/etc/init.d/vsftpd restart


PS:

增加用户

#!/bin/bash


if [ "$#" -ne 1 ]; then

    echo "./$0 USER"

    exit 1

fi


USER=$1

WORKDIR=/etc/vsftpd

USERFILE=$WORKDIR/vuser_passwd.txt

USERCONF=$WORKDIR/vuser_conf/$USER


grep -q -w "$USER" $USERFILE

if [ "$?" -eq 0 -o -d "/data/$USER" ]; then

    echo "ERROR: $USER already exist!"

    exit 1

fi


mkdir -p /data/$USER

chown -R ftp:ftp /data/$USER

cat > $USERCONF << EOF

local_root=/data/$USER

write_enable=YES

anon_umask=022

anon_world_readable_only=NO

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_other_write_enable=YES

EOF


python=`which python`

password_script="create_passwd.py"

password=$($python $password_script)

echo "$USER" >> $USERFILE

echo "$password" >> $USERFILE


db_load=`which db_load`

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


/etc/init.d/vsftpd restart


echo

echo "ftp_ip      : project.ftp.xinghegame.com"

echo "ftp_user    : $USER"

echo "ftp_password: $password"

echo "ftp_port    : 21"



#!/usr/bin/env python

import random

import string

def create_password(lenth=16):

    s = string.letters + string.digits + '!@#$%^&*_+'

    passwd = ''.join(random.sample(s, lenth))

    return passwd

print create_password()


脚本同步ftp目录及文件

#!/bin/bash

FTPHost="xxxxxx"

FTPUser="ftp"

FTPPasswd="xxxxxx"


LocalDir="/data/package/xxx/resource/xxx/GamePack"  #本地目录

RemoteDir="/update/xxx/GamePack"   #远程ftp目录


# function start, Not nedd to edit!!!

#/usr/bin/svn cleanup ${LocalDir} && /usr/bin/svn update ${LocalDir}


/usr/bin/lftp << EOF

open ftp://${FTPUser}:${FTPPasswd}@${FTPHost}

mirror -R -x ^\.svn/$ -x .svn ${LocalDir} ${RemoteDir}

quit

EOF