1. Computing
Send to a Friend via Email

Net:SSH--Transferring Files with Net::SCP


6 of 6

Downloading Files into Memory

It's not always convenient to save a file to the hard drive, and doesn't make much sense to do so if the file is small and you're going to parse it right away anyway. If you don't pass a local filename to the download! method, it won't save the file, but rather return the file as a String.

#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
require 'net/scp'

hostname = ''
username = 'user'
password = 'pass'

Net::SCP.start( hostname, username, :password => password ) do|scp|
  puts scp.download!('log.txt').split(/\n/).grep(/^ERROR/)
  1. About.com
  2. Computing
  3. Ruby
  4. Networking
  5. SSH
  6. Transferring Files with Net::SCP--Downloading Files into Memory

©2014 About.com. All rights reserved.