安装ftp服务端及客户端
[root@localhost ~]# yum -y install ftp vsftpd
修改vsftpd主配置文件允许上传文件
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
####一下三行去掉注释即可
anon_upload_enable=YES
anon_mkdir_write_enable=YES
chown_uploads=YES
重启vsftpd,并设置开机自启
[root@localhost ~]# systemctl restart vsftpd
[root@localhost ~]# systemctl enable vsftpd
关闭防火墙及selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
创建目录并添加权限
[root@localhost ~]# mkdir /var/ftp/pub/xxx
[root@localhost ~]# chmod -R 777 /var/ftp/pub/xxx/
安装expect
[root@localhost ~]# yum -y install expect
编辑expect脚本
[root@localhost ~]# vim /shell/ftp.exp
#!/usr/bin/expect
spawn ftp localhost
expect "root"
send "anonymous\r"
expect "Password:"
send "\r"
expect "ftp >"
send "cd pub\r"
expect "ftp >"
send "put /tmp/url.txt a.txt\r"
interact
添加权限
[root@localhost ~]# chmod +x /shell/ftp.exp
执行
[root@localhost ~]# cd /shell/
[root@localhost shell]# ./ftp.exp