-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkscpto
executable file
·65 lines (56 loc) · 1.52 KB
/
mkscpto
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env expect --
# vim:ts=4:sw=4:expandtab
#######################################################################
# NAME
# mkscpto - a toy for copy file from local to remote (using scp)
#
# SYNOPSIS
# mkscpto filepath username password hostname hostport hostpath
#
# AUTHORS
# neiku project <[email protected]>
#
# SEE ALSO
# scp
# expect --help
#
# VERSION
# 2015/12/05: 支持使用scp拷贝本地文件到远程机器
# 2015/12/10: 支持rsa验证方式
# 2017/01/16: 支持跨平台
# - 通过env程序+PATH变量动态查询bash,控制权
# 、准确性都得到保障
#
#######################################################################
set filepath "[lindex $argv 0]"
set username "[lindex $argv 1]"
set password "[lindex $argv 2]"
set hostname "[lindex $argv 3]"
set hostport "[lindex $argv 4]"
set hostpath "[lindex $argv 5]"
set timeout -1
send_user "scp '$filepath' to $username@$hostname#$hostport:$hostpath\n"
spawn -noecho scp -C -P$hostport $filepath $username@$hostname:$hostpath
expect {
# say 'yes' for the first connection (passwd)
"(yes/no)?" {
send "yes\r"
# now ask for password
expect "password:"
send "$password\r"
}
# ask for password on non-first connection (passwd)
"password:" {
send "$password\r"
}
# wait for transmission done (rsa)
eof {
exit
}
# error occurred, then exit
"ssh" {
exit
}
}
# wait for transmission done (passwd)
expect eof