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

In reply to Re^2: FTP Get Directory Tree Only by roboticus
in thread FTP Get Directory Tree Only by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.