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

Hi,

I am trying to use the Net::FTP module to get a remote file
where file names (could be multiple files) is only partially known.
I am trying the following which is not working

$host = 'myhost'; $user = 'myuser'; $password = 'mypassword'; $dir = "mydir/mysubdir/"; $file = "myfile"; $ftp = Net::FTP->new($host) or die $!; $ftp->login($user,$password) or die $!; $ftp->cwd("$dir") or die "FTP cwd failed : $!\n"; $ftp->put("$myfile*") or die "FTP put failed : $!\n"; $ftp->quit() or die "FTP quit failed : $!\n";

What would be the best way to do this?

Thanks!

Replies are listed 'Best First'.
Re: using Net::FTP to get a file without a full name
by buckaduck (Chaplain) on Aug 23, 2004 at 22:32 UTC
    This question is discussed in this node.

    buckaduck

Re: using Net::FTP to get a file without a full name
by Aristotle (Chancellor) on Aug 23, 2004 at 22:32 UTC

    You have to glob the wildcard explicitly at the local site. If I understand your question correctly, you want

    for my $file ( glob "$myfile*" ) { $ftp->put( $file ) or die "PUT $file failed: $!\n"; }

    Makeshifts last the longest.

      Hi,

      Sorry, my mistake. I meant to 'GET' file(s) from a remote
      server instead

      Thanks!

        Then you can list the files on the remote site and filter the list with whatever pattern you want to use.
        my @list = $ftp->ls(); my @files = grep { /some pattern.*/ } @list; foreach my $file (@files) { $ftp->get($file); }