环境:Centos7
#!/bin/bash
FTP_HOST='ip'
FTP_USER='用户名'
FTP_PASSWD='密码'
source /etc/profile
expect<<EXP
set timeout
spawn ftp $FTP_HOST
expect "Name*"
send "$FTP_USER\r"
expect "Password:*"
send "$FTP_PASSWD\r"
expect "ftp>*"
send " passive \r"
send "lcd $DATA_DIR \r"
send "get $FTP_FILE_DEVICEINFO $DATA_ORGIN_DEVICEINFO \r"
expect {
"Fail*" { send "get $FTP_FILE_DEVICEINFO $DATA_ORGIN_DEVICEINFO \r" }
"*226" { send_user "download successful !\r"}
}
send "get $FTP_FILE_TENCENT_FILM $DATA_ORGIN_TENCENT_FILM \r"
expect {
"Fail*" { send "get $FTP_FILE_TENCENT_FILM $DATA_ORGIN_TENCENT_FILM \r" }
"*226" { send_user "download successful !\r"}
}
expect {
"*Fail*" { send_user "remote $file No such file";send "quit\r" }
"*226" { send_user "download successful !\r";send "quit\r"}
}
expect eof
EXP