Net :: SFTP无法通过rake任务连接到主机

时间:2018-09-13 13:32:11

标签: ruby ssh net-sftp

我正在尝试编写一个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)

0 个答案:

没有答案