Vanquish has asked for the wisdom of the Perl Monks concerning the following question:

Hi I need to get subdirectories including the files present in them using FTP is there any way i can do it? Thanks V

Replies are listed 'Best First'.
Re: Ftp get directory
by sweetblood (Prior) on May 27, 2004 at 19:38 UTC
    have a look at Net::FTP, It's very straight forward.

    Good luck

    Sweetblood

Re: Ftp get directory
by ChrisR (Hermit) on May 27, 2004 at 19:39 UTC
    After connecting try something like this:
    @remotelist = $ftp->ls("-alR");
    You will have to parse out the contents of the array into something more useful though. I did it like this:
    for my $line(@remotelist) { if($line =~ m/\<DIR\>/){ next; } # item is a directory elsif($line =~ m/^\n$/){ next; } # item is a blank line (nix type) elsif(length($line) == 0){ next; } # really blank line elsif($line =~ m/^\.\\(.*?):$/) # we have changed directories { $curdir = $1; $curdir =~ s/\\/\//g; # change the direction of the slash $curdir = $parent . $curdir; } elsif($line =~ /(\d{2}-\d{2}-\d{2})\s+(\d{2}:\d{2}..)\s+(\d+)\s+(. +*?)$/) # item is a file { # name date time size; push @{$listing{$curdir}}, [ $4, $1, $2, $3 ]; } else { print "---> UNKNOWN:\n" . length($line) . "\n|$line|\n"; }
    I hope this helps.