我在目录usr/share/ruby.rb
中有一个文件。我想使用SSH和SCP使用Ruby调用将该文件传输到基于IP的远程设备。任何人都可以帮助我吗?
答案 0 :(得分:21)
示例:
require 'net/scp'
host = '10.10.10.10'
login = 'foo'
password = 'bar'
Net::SCP.start(host, login, :password => password) do |scp|
puts 'SCP Started!'
scp.download('/usr/share/ruby.rb', '.')
end
还有scp.upload
答案 1 :(得分:15)
Net::SSH库包含Net::SCP,因此您应该开始查看。
来自Net :: SCP docs:
require 'net/scp' # upload a file to a remote server Net::SCP.upload!("remote.host.com", "username", "/local/path", "/remote/path", :password => "password") # download a file from a remote server Net::SCP.download!("remote.host.com", "username", "/remote/path", "/local/path", :password => password) # download a file to an in-memory buffer data = Net::SCP::download!("remote.host.com", "username", "/remote/path")