upload - Account locked due to 6 failed logins occurred when using expect script to call sftp to upload file
问题描述
I have written an expect script in which i call sftp to upload file and i pass sftpuser sftppass sftpip to the script. In shell, i call this script with same right parameter and it will upload file successfully five times. And in the sixth turn, it reports the following error: Account locked due to 6 failed logins
I doubt that i have passed the right password every time, why system treat it as an failure login?
The expect script looks like this:
#!/usr/bin/expect -f
set loginuser [lindex $argv 0]
set loginpass [lindex $argv 1]
set ipaddr [lindex $argv 2]
set remote_dir [lindex $argv 3]
set put_file [lindex $argv 4]
set timeout 300
set cmd_prompt "sftp>"
#-------------------------------------------------- login by ssh
spawn sftp $loginuser@$ipaddr
set timeout 300
expect {
-re "Are you sure you want to continue connecting (yes/no)?" {
send "yes\r"
} -re "assword:" {
send "$loginpass\r"
} -re "Permission denied, please try again." {
exit
} -re "Connection refused" {
exit
} timeout {
exit
} eof {
exit
}
}
expect {
-re "assword:" {
send "$loginpass\r"
}
-re $cmd_prompt {
send "\r"
}
}
exec sleep 1
expect {
-re $cmd_prompt {
send "cd $remote_dir\r"
}
}
#exec sleep 1
#expect {
#-re $cmd_prompt {
#send "ls\r"
#}
#}
exec sleep 1
expect {
-re $cmd_prompt {
send "put $put_file\r"
}
}
expect {
-re $cmd_prompt {
send "exit\r"
}
}
expect eof
#interact
The command calling this script in shell looks like this: ./autoftp.sh sftpuser sftpuserpass 172.11.11.11 upload ./test.dat
解决方案
要查看到底发生了什么,请使用-d
调试标志运行 expect 并仔细研究结果输出。
其他一些观察:
- 您所有的期望模式都有
-re
标志,这意味着将它们视为正则表达式,但它们实际上不是正则表达式,除了第一个,问号会被误解。您应该使用该-ex
标志进行精确匹配。 - 除非您安装了非常旧的 Expect/Tcl,否则五行 [lindex $argv *] 可以压缩为
lassign $argv loginuser loginpass ipaddr remote_dir put_file
. - Expect 有自己的功能
sleep
,所以你不需要.exec sleep 1
sleep 1
- 而不是复制密码处理,当您匹配时
"Are you sure you want to continue connecting (yes/no)?"
将处理程序更改为
{ send "yes\r" exp_continue }
重新启动相同的期望命令。
推荐阅读
- blockchain - IPFS bizantine 容错吗?
- swift - 是否可以将自定义 UITableViewCell 存储到数组中?
- python - 打印语句中的 For Loop 将生成器功能作为输出
- amazon-web-services - 无法使用 kops 在 AWS 上安装 Kubernetes
- java - 在 Hibernate 中为 LocalDateTime 创建列类型 Datetime
- c# - 将 DLL 转换为 XSD
- android - EditText“maxLines”属性不起作用
- c++ - Windows C++:文件夹移动访问被拒绝错误
- robotframework - 如何在机器人框架中设置元素属性
- python - Odoo 10 - 带有 onchange 的函数