python 实现自动远程登陆scp文件实例代码

时间:2021-07-19 06:08:04

 python 实现自动远程登陆scp文件实例代码

实现实例代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/expect
 
 
if {$argc!=3} {
send_user "Usage: $argv0 {path1} {path2} {Password}\n\n"
exit
}
set path1 [lindex $argv 0]
set path2 [lindex $argv 1]
set Password [lindex $argv 2]
 
 
spawn scp ${path1} ${path2}
 
 
expect {
"Password:" {
exec sleep 1
send "${Password}\r"
}
"*continue connecting*" {
exec sleep 1
send "yes\r"
expect "*Password:" {
exec sleep 1
send "${Password}\r"
}
 
}
}
expect "*"
send "exit\r"
expect "*closed*"
#send "exit\r"
#expect "*"
#exit
#exec sleep 10

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!