From: Lincoln Anderson Date: 2006-09-13T02:25:58+09:00 Subject: Re: Net::FTP questions... -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Vincent Arnoux wrote: > Le mercredi 13 septembre 2006 à 00:14 +0900, James Cribbs a écrit : > Lincoln Anderson wrote: >> Here's where my problem comes in. How can I tell from the list >> array whether an item is a directory or a file to be copied? Is >> there something I can use (such as an FTP command) to catch a >> clue on how to implement this? I know this is possible, as >> ftpmirror is done with PERL and Ruby can do anything PERL can do >> - better :) > > Perhaps this can be useful to browse the FTP server tree (directory > names finish by '/', others are files): > > def recursive_listing(ftp, path) liste_ftp = Array.new list = > ftp.ls(path) if list.length == 0 return [] end if list[0].split[0] > == 'total' list.delete_at(0) end if list[0].split[8] == '.' > list.delete_at(0) end if list[0].split[8] == '..' list.delete_at(0) > end list.each { |str| if str.split[0].index('d') == 0 liste_ftp += > [path + "/" + str.split[8] + "/"] liste_ftp += > [recursive_listing(ftp, path + "/" + str.split[8])] else liste_ftp > += [path + "/" + str.split[8]] end } return liste_ftp.flatten end > > ftp = Net::FTP.new('ftp_serveur') ftp.login('login', 'passwd') > ftp_list = recursive_listing(ftp, 'starting_directory') ftp.close > > > It might need some corrections depending your FTP server > configuration. > > Cheers, Vincent > > > > > That looks exactly like what I'm trying to do for the directory hierarchy mirror. I'm still learning to think in Ruby... I keep going back to C/C++ solutions and other heavy hitter languages... I'll tweak that and see if I can get it working. I'll post my results when I get it running (or I have any other insurmountable problems...). Thanks, Lincoln Anderson -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFBu1+Kte2c0P8BH0RAgj9AJ93sCYtnfq8FKx6MmlgGqEYm46RTQCeOi6L mkZjNSXuR+vpn1JrgPZORaQ= =CfgK -----END PGP SIGNATURE-----