将远程位置的内容复制到ruby脚本中的本地文件

时间:2016-02-24 02:25:57

标签: ruby ruby-on-rails-3

我想在建立ssh连接后将远程位置文件的内容复制到某个本地文件。

 begin
    ssh = Net::SSH.start("localhost", "user")
    logger.info "conn successful!"
    results = conn.exec!('ruby somefile "#{arguments}"')
    #code to copy the contents of a.txt in remote location to local file
    #IO.copy_stream (localfile, remotefile)
 rescue
    logger.info "error - cannot connect to host"
 end

我尝试使用IO.copy_stream,但这不起作用。我该怎么做?

1 个答案:

答案 0 :(得分:0)

使用Net::SCP.download!("remote.host.com", "username", "/remote/path", "/local/path", :password => password) (需要Net :: SSH)传输文件:

{{1}}

此处有更多信息:https://rubygems.org/gems/net-scp