我正在尝试在我的 Ruby 代码中使用 SSH 登录到远程机器,然后在我通过 SSH 登录后尝试 cd 到另一个目录。这是我的 Ruby 代码来执行此操作
require 'net/ssh'
require 'rubygems'
require 'needle'
Net::SSH.start('host', 'shui', :password => "password") do |ssh|
output = ssh.exec!("hostname")
shell = ssh.shell.open
shell.pwd
shell.cd "/svn"
puts shell.pwd
end
当我运行我的脚本时,它给我这个错误:
testssh.rb:8:in `block in <main>': undefined method `shell' ... (NoMethodError)
我很确定我已经安装了执行此操作所需的 gem。对于如何解决这个问题,有任何的建议吗?谢谢!
最佳答案
Net:SSH v2
中没有shell
方法,生成的对象是一个 Net::SSH::Connection::Session。 .
此 net-ssh
扩展为您提供了您正在寻找的功能:https://github.com/mitchellh/net-ssh-shell
关于Ruby Net::SSH 未定义方法 'shell',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11942579/