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

copy contents of a remote location to a local file in ruby script

我想在建立 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 但那不起作用。我该怎么做?

使用Net::SCP(需要Net::SSH)传输文件:

Net::SCP.download!("remote.host.com", "username",
  "/remote/path", "/local/path",
  :password => password)

更多信息在这里:https://rubygems.org/gems/net-scp