Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

using Net::FTP to get a file without a full name

by tariqahsan (Beadle)
on Aug 23, 2004 at 22:24 UTC ( [id://385251]=perlquestion: print w/replies, xml ) Need Help??

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); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://385251]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found