> Leo Durocher wrote:
> 
> Hi all,
>         There is a file I have to get at least once a week. The end of the file name 
>changes each time.  I would like  to connect to the server go to the directory, list 
>the file and get it.
> 
> The file name as an example would be ABC123XXXX.exe     The X's is what changes.
> 
> Chan anyone help with this.  I have Perl v5.6.1 built for MSWin32-x86-multi-thread
> (with 1 registered patch)  Binary build 629 from Activestate

Untested:

use strict;

use Net::FTP;

my $host = '';
my $user = '';
my $pass = '';
my $dir = '';

my $ftp = Net::FTP->new ($host) or die "Error connecting to $host: $!\n";
$ftp->login($user,$pass) or die "Error logging in to $host: $!\n";
$ftp->cwd($dir) or die ("Error cd $dir\n");
$ftp->binary() or die ("Error setting binary mode\n");

my $files = $ftp->dir();        # get remote dir

# loop through files in dir (you could use grep instead)

OUTER:
foreach (@$files) {

        next if /^[^-]/;        # skip lines not starting with -

        my $file = (split /\s+/, $_, 9)[8];     # get filename

        next if $file !~ /^ABC123(.*?)\.exe/;   # my file ?

        # found my file if got here

        $ftp->get ($file, "./$file") or die ("Error getting $file\n");

        last;
}
$ftp->quit;     # disconnect

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED] 
  / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin

Reply via email to