1. Computing
Send to a Friend via Email

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

By

5 of 6

Recursive Uploads and Downloads

Both the upload and download method can act recursively. This means that, given a directory name instead of a filename, will upload or download an entire directory tree. To get this behavior, pass a directory name to the upload or download methods and add the :recursive => true option to the method call. This example will download the logs directory and all its files, including all subdirectories and all their files, to the current directory on the local machine.

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

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

Net::SSH.start( hostname, username, :password => password ) do|ssh|
  ssh.scp.download!( 'logs', '.', :recursive => true )
end
  1. About.com
  2. Computing
  3. Ruby
  4. Networking
  5. SSH
  6. Transferring Files with Net::SCP--Recursive Uploads and Downloads

©2014 About.com. All rights reserved.