- require 'net/ssh'
require 'net/sftp'
host = hostip
username = username
password = password
#~ ##显示文件和系统版本
server_cmd1 = 'ls -l'
server_cmd2 = 'cat /etc/issue'
# 需要安装以下组件
#gem install net-ssh
#gem install net-sftp
Net::SSH.start(host, username, :password => password) do |ssh|
puts ssh.exec!(server_cmd1)
puts ssh.exec!(server_cmd2)
ssh.sftp.connect do |sftp|
Dir.foreach('.') do |file|
puts file
end
end
end
类似文章:http://www.infoq.com/cn/articles/ruby-file-upload-ssh-intro
以上就是在ruby下使用ssh方式连接linux服务器的详细内容,更多关于在ruby下使用ssh方式连接linux服务器的资料请关注九品源码其它相关文章!