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

I am using Net:FTP and need a script to ftp to a server and retreive files without knowing the names of these files. Is there something like $ftp->get("%", "PATH"); and % is a wildcard? Thanks, -Mitch

Replies are listed 'Best First'.
Re: Using NET::FTP with Unkown File Names
by lhoward (Vicar) on Jul 06, 2001 at 23:17 UTC
    No Net::FTP does not support wildcards directly, but Net::FTP has an ls method that you can use to get a list of files on the remote server. Then just loop through this list and download them...
    use Net::FTP; $ftp = Net::FTP->new("some.host.name", Debug => 0); $ftp->login("anonymous",'me@here.there'); $ftp->cwd("/pub"); my @l=$ftp->ls(); foreach(@l){ $ftp->get($_); } $ftp->quit;
    be sure to add error checking code to the above for "real live" use
      As an additional sanity check, you may want to add something like
      if ( $ftp->size($remoteFileName) <> -s $localFileName) { die "file size mismatch\n"; }
      after the transfer. We have seen cases where the get() succeeded but the file was not complete.