FTP Service build script and client FTP automatic upload script

Source: Internet
Author: User
Tags ftp connection

Linux Servers build FTP service scripts (tested on centos6.5 and CENTOS7) (the script does not make a judgment and needs to clean up the environment itself) (the script only allows uploads to not allow downloads, and does not allow anonymous users and local users to log on)

Installation scripts

#!/bin/bash
Source/etc/rc.d/init.d/functions
#安装vsftpd
Rpm-q vsftpd
If [$?-ne 0];then
Yum Install-y vsftpd
Fi
#备份主配置文件
Cp/etc/vsftpd/ftpusers{,.bak}
Cp/etc/vsftpd/user_list{,.bak}
Cp/etc/vsftpd/vsftpd.conf{,.bak}
#创建虚拟用户
Read-p "Input username (default tom):" username
Username=${username:-tom}
Read-p "Input user password (default 123456):" Password
password=${password:-123456}
Read-p "Input FTP Home (default/usr/+ $USERNAME):" Ftphome
ftphome=${ftphome:-"/usr/$USERNAME"}
Read-p "Input virtual username (default test):" VName
Vname=${vname:-test}
Read-p "Input Virtual user passwd (default $VNAME):" vpasswd
vpasswd=${vpasswd:-"$VNAME"}
echo $USERNAME $PASSWORD $FTPHOME $VNAME $VPASSWD
#read-P

#修改主配置文件
Cat >/etc/vsftpd/vsftpd.conf << EOF
Listen_port=21
Write_enable=yes
local_umask=022
Xferlog_enable=yes
Xferlog_file=/var/log/vsftpd.log
Connect_from_port_20=no
data_connection_timeout=1200
Listen=yes
max_clients=10
Setproctitle_enable=yes
Anonymous_enable=no
Local_enable=yes
Anon_upload_enable=no
Anon_mkdir_write_enable=no
Chroot_local_user=yes
Dirmessage_enable=yes
Ftpd_banner=welcome to blah FTP service.
Guest_enable=yes
Pam_service_name=/etc/pam.d/vsftpd.virtual
Guest_username= $USERNAME
Virtual_use_local_privs=yes
User_config_dir=/etc/vsftpd/vhome
Userlist_enable=yes
Userlist_deny=yes
Tcp_wrappers=yes
#被动模式, the default is Yes
Pasv_enable=yes
#pasv_min_port =1024
#pasv_max_port =2048
Download_enable=no
Eof

#创建宿主用户
useradd-d $FTPHOME-S/sbin/nologin $USERNAME
echo $PASSWORD |passwd--stdin $USERNAME
#创建虚拟用户宿主目录, for virtual user logon access
MKDIR-PV $FTPHOME
Chown-r $USERNAME. $USERNAME "$FTPHOME"
#创建虚拟用户
Cat >/etc/vsftpd/vusers.txt << EOF
$VNAME
$VPASSWD
Eof
Db_load-t-T Hash-f/etc/vsftpd/vusers.txt/etc/vsftpd/vsftpd-virtual-user.db
#创建pam认证配置文件, specify the database file path
Cat >/etc/pam.d/vsftpd.virtual << EOF
Auth required/lib64/security/pam_userdb.so Db=/etc/vsftpd/vsftpd-virtual-user
Account Required/lib64/security/pam_userdb.so Db=/etc/vsftpd/vsftpd-virtual-user
Eof
#创建虚拟用户配置信息存放目录
Mkdir-pv/etc/vsftpd/vhome
#在目录下对虚拟用户进行权限分配
Cat >/etc/vsftpd/vhome/$VNAME <<eof
Anon_world_readable_only=no
Anon_upload_enable=yes
Anon_mkdir_write_enable=yes
Anon_other_write_enable=yes
anon_umask=033
local_root= $FTPHOME
Eof
#重启vsftpd服务
Service VSFTPD Restart

vsftpd.conf configuration file Explanation

#监听端口listen_port =21# Allow write write_enable=yes# settings umasklocal_umask=022# enable log xferlog_enable=yes# set log path Xferlog_file=/var /log/vsftpd.log# Specifies that FTP uses port 20 for data transfer, and the default value is yes. Connect_from_port_20=yes#ftp data connection timed out, default 120sdata_connection_timeout=1200# uses standalone mode to run listen=yes# maximum number of connections, The default of 0 means that unrestricted max_clients=10# host FTP connections are displayed in different processes, by default nosetproctitle_enable=yes# anonymous user logon, set to noanonymous_enable=no# local user logon , set to nolocal_enable=no# anonymous user uploads, set to noanon_upload_enable=no# anonymous users have permission to create directories. Set to noanon_mkdir_write_enable=no# whether the user is running the switch to the parent directory, the default is No,yes when all users cannot switch to another directory (Cage mode) chroot_local_user=yes# Set welcome language Dirmessage_enable=yesftpd_banner=welcome to blah ftp service. #启用虚拟用户guest_enable =yes# The name pam_service_name=/etc/pam.d/vsftpd.virtual# used by the virtual user Pam uses the host user name guest_username=ftphost# let the virtual user have the permissions of the local host user Virtual_ use_local_privs=yes# Define user Profiles user_config_dir=/etc/vsftpd/vhome# whether userlist files are enabled userlist_enable=yes# Whether to allow user access userlist_deny=yes# in userlist with Tcp wrapper for host access control tcp_wrappers=yes# whether passive mode pasv_enable=yes# passive mode port range is enabled , the default of 0 means any #pasv_min_port=1024#pasv_max_port=2048# disable downloading of files to local Download_enable=no 

Linux uses passive mode to automatically upload file scripts


Rpm-q FTP
If [$?-ne 0];then
Yum install-y FTP
Fi
echo "Start FTP Update"
#-N: Not affected by the. netrc file,<<: Using instant file redirection input

Open IP Pord
User Username password
Passive
Binary
CD DIR
Lcd/local/dir
Prompt
Mput *
Close
Bye
Eof

Put command explanation

Open to establish a specified FTP server connection, default port 21
User connection Password
Passive using passive mode
Binary binary transfer mode (no modifications to the file will be done)
CD Switch Remote FTP command
LCD Switch Local Directory
Prompt closing interactive mode
Mput Uploading Files
Close to disconnect the FTP connection
Bye exiting FTP

Windows automatic upload script (need to turn on passive mode)

@Echo OFF
:: "Set PATH environment variable"
Set Path=c:\windows\system32; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\
:: "Switch to execution directory"
C:
CD C:\Users\Administrator\Desktop\test
:: "writes the executed option to the file, and then calls the"
Echo Open IP PORT >ftp.up
Echo Username>>ftp.up
Echo Password>>ftp.up
Echo Binary>>ftp.up
Echo Cd DIR >>ftp.up
Echo LCD C:\users\administrator\desktop\test\dir>>ftp.up
Echo Prompt>>ftp.up
Echo mput *>>ftp.up
Echo Close>>ftp.up
Echo Bye>>ftp.up
:: "Execute FTP command, invoke Configuration"
Ftp-s:ftp.up
:: "Delete generated configuration file"
Del ftp.up/q

Just a brief explanation.

Open connection FTP, followed by FTP server user, disconnected

Username FTP connection User name

Password FTP connection password

Binary using binary transfer mode

CD Switch Remote FTP directory

LCD switching local Exposure

Prompt closing interactive mode

windows open FTP Passive mode

Open IE--tools-->internet option--------check "Use Passive FTP"

Reference:

VSFTPD Reference Document:http://blog.51cto.com/yuanbin/108262

FTP command explanation:http://blog.csdn.net/zzzzcs/article/details/23995833

FTP Service Build script and client FTP automatic upload script

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.