-
Notifications
You must be signed in to change notification settings - Fork 391
Expand file tree
/
Copy pathsftpUploadFile
More file actions
executable file
·48 lines (36 loc) · 1.09 KB
/
sftpUploadFile
File metadata and controls
executable file
·48 lines (36 loc) · 1.09 KB
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
#!/usr/bin/expect -f
#--------------------------------------------
# 功能:使用sftp将当前路径下指定文件上传到服务器指定路径中
# 使用说明:命令有5个参数。注意:目前该脚本无参数验证功能,必须5个参数,否则脚本运行结果会发生错误
# 参数1:要上传的文件名
# 参数2:服务器地址
# 参数3:sftp用户名
# 参数4:sftp密码
# 参数5:sftp工作路径
# 作者:ccf
# E-mail:ccf.developer@gmail.com
# 创建日期:2013/02/27
#--------------------------------------------
#参数设置
set uploadFileName [lindex $argv 0]
set host [lindex $argv 1]
set username [lindex $argv 2]
set password [lindex $argv 3]
set hostfilepath [lindex $argv 4]
#sftp连接
spawn sftp $username@$host
#第一次sftp时需输入yes
expect {
"(yes/no)?" {send "yes\r"; exp_continue}
"password:" {send "$password\r"}
}
#切换到所要放置的目录下
expect "sftp>"
send "cd $hostfilepath\r"
#从服务器上下载指定
expect "sftp>"
send "put $uploadFileName\r"
#退出sftp
expect "sftp>"
send "bye\r"
expect eof