lib/fig/os.rb
def ssh_download(user, host, path, cmd)
      return_code = nil
      tempfile = Tempfile.new("tmp")
      Net::SSH.start(host, user) do |ssh|
        ssh.open_channel do |channel|
          channel.exec(cmd)
          channel.on_data() { |ch, data| tempfile << data }
          channel.on_extended_data() { |ch, type, data| $stderr.puts "SSH Download ERROR: #{data}" }
          channel.on_request("exit-status") { |ch, request|
            return_code = request.read_long
          }
        end
      end

      tempfile.close()

      case return_code
      when NOT_MODIFIED
        tempfile.delete
        return false
      when NOT_FOUND
        tempfile.delete
        raise "File not found: #{path}"
      when SUCCESS
        FileUtils.mv(tempfile.path, path)
        return true
      else
        tempfile.delete
        $stderr.puts "Unable to download file: #{return_code}"
        exit 1
      end
    end
# path = The local path the file should be downloaded to.
# cmd = The command to be run on the remote host.
path = The local path the file should be downloaded to.
cmd = The command to be run on the remote host.
path = The local path the file should be downloaded to . cmd = The command to be run on the remote host .
def ssh_download(user, host, path, cmd)
      return_code = nil
      tempfile = Tempfile.new("tmp")
      Net::SSH.start(host, user) do |ssh|
        ssh.open_channel do |channel|
          channel.exec(cmd)
          channel.on_data() { |ch, data| tempfile << data }
          channel.on_extended_data() { |ch, type, data| $stderr.puts "SSH Download ERROR: #{data}" }
          channel.on_request("exit-status") { |ch, request|
            return_code = request.read_long
          }
        end
      end
      tempfile.close()
      case return_code
      when NOT_MODIFIED
        tempfile.delete
        return false
      when NOT_FOUND
        tempfile.delete
        raise "File not found: #{path}"
      when SUCCESS
        FileUtils.mv(tempfile.path, path)
        return true
      else
        tempfile.delete
        $stderr.puts "Unable to download file: #{return_code}"
        exit 1
      end
    end
def ssh_download ( user , host , path , cmd ) return_code = nil tempfile = Tempfile . new ( "tmp" ) Net :: SSH . start ( host , user ) do | ssh | ssh . open_channel do | channel | channel . exec ( cmd ) channel . on_data ( ) { | ch , data | tempfile << data } channel . on_extended_data ( ) { | ch , type , data | $stderr . puts "SSH Download ERROR: #{data}" } channel . on_request ( "exit-status" ) { | ch , request | return_code = request . read_long } end end tempfile . close ( ) case return_code when NOT_MODIFIED tempfile . delete return false when NOT_FOUND tempfile . delete raise "File not found: #{path}" when SUCCESS FileUtils . mv ( tempfile . path , path ) return true else tempfile . delete $stderr . puts "Unable to download file: #{return_code}" exit 1 end end
path = The local path the file should be downloaded to.
path = The local path the file should be downloaded to .
user
host
path
cmd