[olug] ftp problem - downloading 1 of 2 files that share same name

Terry td3201 at gmail.com
Mon Aug 16 15:37:04 UTC 2004


Hello,

I have an interesting problem.  I am downloading files from a
proprietary 'ftp' server.   Here is an ls:

-ARTE-----TCP A ceunix        106   399948 Jun 23 14:31 02440029.INS
-ART------TCP A ceunix       1842   399948 Aug 12 10:52 02440029.INS

The ARTE 'permissions' mean that the file is not available for
download.  You get an error if you try to download it.  I need to
download the file without the E in the permissions somehow.

When I do a 'get 02440029.INS', it will grab the first one in the list
which is the one I don't want.  This process is mean to be done with a
graphical client that allows you to differentiate between the files
and grab the right one.  How can I do this?  I am attempting this with
Perl.  Be gentle, my code sucks.  You can see that I tried to grab
lines that do not contain ARTE but that was just stupid because
ftp->get will still grab the first file it sees regardless of the
limits I put in place.  I stripped out some irrelevant stuff so I may
have botched some code:

use Net::FTP;

$username = 'foo';
$password = 'bar';
$host = 'ftp.foo.com';
$ftp = Net::FTP->new("$host", Port => 10021,Debug => 0)
        or die "Cannot connect to $host: $@";
$ftp->login("$username","$password")
        or die "Cannot login ", $ftp->message;
$ftp->ascii;
@lines = $ftp->ls;
foreach $foo ( @lines ) {
        unless ( $foo eq 'outgoing' || $foo =~ /batch/ || $foo =~ /ARTE/ )
        {
                if ( $foo =~ /\w*\s\w*/ )
                {
                        @elem = split( /\s+/, $foo );
                        $file = $elem[8];
                                $ftp->get("$file")
                                        or die "get failed ", $ftp->message;
                }
        }
}
$ftp->quit;


Thanks,
Terry



More information about the OLUG mailing list