防火墙关掉!

1 安装expect命令

yum -y install expect

2 vim ftp_upload.sh
#!/usr/bin/expect
spawn ftp localhost #执行ftp命令
expect “Name*” #如果出现Name字符
send “ftp\n” #则输入ftp并回车
expect “ftp>"
send “cd pub/other\n”
expect "ftp>

send “put /tmp/123.txt xo.txt\n”
expect {
“150 Ok to send data” { send_user “upload sucessfull!”;send “quit\n” } #send_user 类型shell的echo命令
“553*” { send_user “upload error!”;send “quit\n” }
}
expect eof #expect eof,与spawn对应,表示捕捉终端输出信息终止,类似if…endif
3 加权限 chmod +x ftp_upload.sh
4 执行命令 ./ftp_upload.sh

使用expect ftp免交互上传文件

相关文章:

  • 2021-08-19
  • 2021-06-19
  • 2021-07-05
  • 2022-12-23
  • 2021-12-26
  • 2022-02-23
  • 2021-11-15
猜你喜欢
  • 2021-11-14
  • 2022-12-23
  • 2021-10-11
  • 2022-02-18
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案