[ 登录注册 ]

云计算

远程获取文件

2016-08-25 21:32:01 admin 返回上一页

#!/usr/bin/expect

set HOSTIP [lindex $argv 0]
set USERNAME [lindex $argv 1]
set PASS [lindex $argv 2]
set CMD_CD [lindex $argv 3]
set CMD_LCD [lindex $argv 4]
set CMD_GET_FILE [lindex $argv 5]
set timeout 10

if {$argc<6} {
        puts stderr "Usage:$argv0 hostip login password destdir srcdir file cmd.\n"
        exit 1
}

spawn sftp $USERNAME@$HOSTIP
expect {
"*yes/no)" {send "yes\r";exp_continue}
}
expect {
"Password:*" {send "$PASS\r";exp_continue}
}
expect "sftp>"
send "$CMD_CD\r"
expect "sftp>"
send "$CMD_LCD\r"
expect "sftp>"
send "$CMD_GET_FILE\r"
expect "* Transfer complete."
send "exit\r"

 注:执行该脚本,需要传入ip地址,用户名,密码,远程目录,本地目录,获取远程文件的路径


文章来源:http://www.bozhiyue.com/cloud/2016/0825/432556.html
返回上一页    返回分类 上一篇:   下一篇:
相关