<pre name="code" class="plain">vim exec_expect_sftp.sh
#/usr/bin/expect -f
#参数1 usrname 参数2 passwd 参数3 ip 参数4 dir
set userna [lindex $argv 0]
set passwd [lindex $argv 1]
set ip [lindex $argv 2]
set dir [lindex $argv 3]
spawn sftp $userna@$ip
expect {
"(yes/no)?" {send "yes\r"; expect_continue}
"password:" {send "$passwd\r"}
}
expect "sftp>"
send "cd $dir\r"
expect "sftp>"
send "get *.*\r"
expect "sftp>"
send "bye\r"
expect eof
/usr/bin/expect exec_expect_sftp.sh usrname passwd ip dir
linux shell使用expect实现sftp的自动交互
最新推荐文章于 2025-03-10 15:00:33 发布