我正在尝试编写一个 rake 任务,它使用 sftp 自动连接到Experian主机。
来自 Experian 的人给了我这个命令,让我使用 SFTP 连接到他们的服务器:
sftp -o PreferredAuthentications=password -o PubkeyAuthentication=no username@experian_ip
当我在终端上运行它时,它工作得很好。
然后我根据该命令编写了一个 rake 任务:
require 'net/sftp'
task :experian_sts => [:environment] do
hostname = "experian_ip"
username = "username"
password = "password"
@cmd = "test"
begin
sftp = Net::SFTP.start(hostname, username, password: password, keys_only: false, number_of_password_prompts: 0)
res = sftp.exec!(@cmd)
sftp.close
puts res
rescue
puts "Unable to connect to #{hostname} using #{username}/#{password}"
end
end
但这项任务似乎不起作用。有什么帮助吗?
更新
删除救援后看到错误:
rake aborted!
Net::SSH::Disconnect: disconnected: Too many bad authentication attempts! (11)
/Users/ryzal/Sites/rentlord/lib/tasks/experian_sts.rake:12:in `block in <top (required)>'
/Users/ryzal/.rbenv/versions/2.3.1/bin/bundle:22:in `load'
/Users/ryzal/.rbenv/versions/2.3.1/bin/bundle:22:in `<main>'
Tasks: TOP => experian_sts
(See full trace by running task with --trace)