in reply to Re: FTP Get Directory Tree Only
in thread FTP Get Directory Tree Only

Two other ideas:
1) I haven't tried it, but while reviewing the man page for wget, I noticed the option --delete-after. Perhaps it would leave the directory structure behind after getting and deleting the local files.
2) A while ago, i wrote a program using Net::FTP to get hierarchical collections of files. I just chopped it up to give you a starting point:
#!/usr/bin/perl -w #============================================================== # GetDirHierarcy.pl #============================================================== use strict; use warnings; use Net::FTP; my $host = 'your.ftp.server'; my $uid = 'user_id'; my $pwd = 'pa$$word'; my $ftph = Net::FTP->new($host) or die "Can't connect to $host"; $ftph->login($uid,$pwd) or die "Can't login"; &GetFiles("."); $ftph->quit; sub GetFiles { my $pref = shift; # NOTE: Assumes UNIX ls format! #my @DirList = grep {/^d/} $ftph->ls; my @DirList = $ftph->dir; for my $DirEnt (@DirList) { next if $DirEnt !~ /^d/; my $DirName = (split / +/, $DirEnt, 9)[8]; my $newpref = $pref . '/' . $DirName; print "mkdir $newpref;\n"; $ftph->cwd($DirName); GetFiles($newpref); $ftph->cwd(".."); } }
Running this against an FTP server I have access to gives:
$ ./GetDirStruct.pl mkdir ./Files; mkdir ./Files/Bar; mkdir ./Files/Bar/Baz; mkdir ./Files/Foo; mkdir ./Inquiry; mkdir ./NpcIN; mkdir ./Processing; mkdir ./Security; mkdir ./Sysmenu;
Just edit the print statement to actually make it create the directory hierarchy.
NOTE: You may encounter an oddball FTP server that uses a different format for the DIR command. (I don't think that the results of the DIR command are in the FTP standard.) So you may have to edit the directory-name parsing portion of the code for your server. (I ran into this problem on an IBM mainframe FTP server.)
--roboticus