1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

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


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 = ''
username = 'user'
password = 'pass'

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

©2014 About.com. All rights reserved.