From: ara.t.howard@... Date: 2006-05-10T04:27:58+09:00 Subject: Re: FTP#mget, FTP#mput On Wed, 10 May 2006, Daniel Berger wrote: > Hi all, > > Is there a method in Net::FTP that corresponds to ftp's mget and mput > functions? > > If not, is there any chance of adding this to ftp.rb? > > Thanks, > > Dan > this grabs directories if you give it something like ftpget ftp://host/dir/dir2/* so it's similar to mget #!/dmsp/reference/bin/ruby require 'net/ftp' require 'uri' require 'yaml' def uriparse uri unless uri =~ %r/^ftp/ host, path = uri.split %r|:/+|o URI::parse "ftp://#{ host }/#{ path }" else URI::parse uri end end abort "#{ $0 } srcuri [srcuris]+ dst" if ARGV.empty? user = ENV["FTP_USER"] || "anonymous" password = ENV["FTP_PASS"] || ENV["FTP_PASSWORD"] || "foo@bar.org" debug = ENV['FTP_DEBUG'] ARGV << '.' if ARGV.size == 1 dest = ARGV.pop lpaths = [] while((src = ARGV.shift)) src = uriparse src Net::FTP.open(src.host) do |ftp| ftp.debug_mode = true if debug ftp.login user, password ftp.passive = true ftp.binary = true paths = [] if src.path =~ %r|\*$|o dir = File::dirname(src.path) ftp.list(src.path) do |listing| path = listing.split(%r/\s+/o).last paths << File::join(dir, path) end else paths << src.path end paths.each do |path| lpath = if test ?d, dest File::join(dest, File::basename(path)) else dest end ftp.getbinaryfile path, lpath lpaths << lpath end end end y lpaths -a -- be kind whenever possible... it is always possible. - h.h. the 14th dali lama