# NET::SFTP downloading multiple directories

**URL:** <https://www.ruby-forum.com/t/net-sftp-downloading-multiple-directories/139175>\
**Category:** Ruby\
**Created:** [June 1, 2008, 1:08am UTC](https://www.ruby-forum.com/t/net-sftp-downloading-multiple-directories/139175 "2008-06-01T01:08:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [June 1, 2008, 1:08am UTC](https://www.ruby-forum.com/t/net-sftp-downloading-multiple-directories/139175/1 "2008-06-01T01:08:10Z")

</div>

Hi guys,

Im pretty new to ruby, and I want to re-write a bash script I wrote to  
backup some data on an iphone to a local comp, in ruby.

This is the bash version: [http://pastebin.com/m1a34a96](http://pastebin.com/m1a34a96)

Here is what i have in ruby so far: [http://pastebin.com/m1c2282c0](http://pastebin.com/m1c2282c0)

What I basically want to do is have an array of remote directories  
downloaded via stfp to a local folder in a loop, or something to this  
effect, and I cant seem to figure it out…

Any help is greatly appreciated!!

-Chris

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [June 1, 2008, 9:15am UTC](https://www.ruby-forum.com/t/net-sftp-downloading-multiple-directories/139175/2 "2008-06-01T09:15:27Z")

</div>

Ok so I got a little further with this, but its still not working  
perfectly… I think the wait method is screwing things up, because I  
only get the contents of the first folder.

#!/usr/bin/env ruby

require ‘FileUtils’  
require ‘net/sftp’

$local\_dir = ‘/iBak’ + Time.now.strftime("%m\_%d\_%y")  
$user\_name = ‘root’  
$backup\_dirs = [’/Applications’,  
‘/var/root/Library/Customize2’,  
‘/var/mobile/Library/Installer’,  
‘/var/mobile/Media/EBooks’,  
‘/var/preferences’  
]  
puts “Please enter your iPhones IP address:”  
$phone\_ip = gets.chomp!  
puts “Now your password:”  
$root\_pass = gets.chomp!  
puts “\nPress enter to begin…”  
gets

FileUtils.mkdir\_p $local\_dir

Net::SFTP.start( $phone\_ip, $user\_name, :password =\> $root\_pass ) do  
|backup|  
dls = $backup\_dirs.map { |f| backup.download!( f, $local\_dir,  
:recursive =\> true) }  
dls.each do |d|  
d.wait  
end  
end

Again, any help would be great!

-Chris
