由远程主机关闭的Ruby net / ssh连接(Net :: SSH :: Disconnect)

时间:2013-11-21 23:27:22

标签: ruby ssh net-ssh

我正在使用net/ssh ssh到服务器并运行命令,我对服务器具有基于密钥的访问权限,并且可以像往常一样在我的终端中使用ssh连接 - 这个问题非常间歇性而且似乎只是偶尔发生没有明显原因。我想知道的是导致这种情况的原因,是否有办法捕获它并在发生连接时重试连接?

错误:

/home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/packet_stream.rb:87:in `next_packet': connection closed by remote host (Net::SSH::Disconnect)
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:172:in `block in poll_message'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:167:in `loop'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:167:in `poll_message'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:204:in `block in wait'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:202:in `loop'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:202:in `wait'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:81:in `initialize'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh.rb:200:in `new'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh.rb:200:in `start'
    from file.rb:58:in `block in <main>'
    from file.rb:35:in `each'
    from file.rb:35:in `<main>'

导致它的代码:

Net::SSH.start(ip, "user") do |ssh|
  result = ssh.exec!("ls -lhtr")
  puts result
end

0 个答案:

没有答案