I have a file in the directory usr/share/ruby.rb
. I want to transfer that file to IP-based remote devices using SSH and SCP using Ruby calls. Can anyone help me?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
example:
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
there's also an scp.upload
回答2:
The Net::SSH library includes Net::SCP, so you should start looking there.
From the 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")