一、安装配置FTP:
# yum -y install vsftpd
# service vsftpd start
# ss -tunlp | grep 21
# useradd ftpuser
# echo 123456 | passwd --stdin ftpuser
# cd /etc/vsftpd/
# cp vsftpd.conf vsftpd.conf.bak
# vim vsftpd.conf
local_enable=YES
write_enable=YES
userlist_enable=YES
userlist_deny=NO
# echo ftpuser > user_list
//禁锢本地用户ftpuser于其家目录中
chroot_local_user=YES
# service vsftpd restart
//安装FTP客户端工具
# yum -y install ftp
# ftp 192.168.199.9
FTP服务器:192.168.199.9
FTP目录:/home/ftpuser,已被chroot至/
本地目录:/software
//让ftpuser用户对/software目录具有写权限
# mkdir -pv /scripts
//从FTP上下载指定文件到本地目录
# vim /scripts/ftp_download.sh
#!/bin/bash
ftp -n -i 192.168.199.9 <<EOF
user ftpuser 123456
binary
cd /
lcd /software
get apache-tomcat-8.0.45.tar.gz
bye
EOF
echo "Download from FTP successfully."
备注:如果要实现批量下载文件,可以将get apache-tomcat-8.0.45.tar.gz修改为mget *
# chmod +x ftp_download.sh
//上传本地指定文件至# vim /scripts/ftp_upload.sh
put apache-tomcat-8.0.45.tar.gz
echo "Upload to FTP successfully."
备注:如果要实现批量上传文件,可以将put apache-tomcat-8.0.45.tar.gz修改为mput *
# chmod +x ftp_upload.sh
说明:
EOF:标识文件的开始和结尾,成对出现
ftp选项:
binary:使用二进制格式传输文件