SPUG: Net::FTP

Martin, Asa asa.martin at attws.com
Wed Aug 7 15:16:48 CDT 2002


I have a directory mirroring script I'm working on and it uses Net::FTP to
connect to the remote host and grab the files. I'm basically using the
ftp_mirror.pl script from Network Programming with Perl by Lincoln Stein.
The script is supposed to compare the time stamp and file size of each file
from the remote server to the local copy and not copy it if it's not newer.
It uses the Net::FTP::mdtm function to get the modification time from the
remote server. 

Here's the code snippet:

zub get_file {

    my ( $path, $mode ) = @_;
    my $rtime = $ftp->mdtm($path);
    my $rsize = $ftp->size($path);
    $mode = ( parse_listing( $ftp->dir($path) ) )[2] unless defined $mode;
    my ( $lsize, $ltime ) = stat($path) ? ( stat(_) )[ 7, 9 ] : ( 0, 0 );
    if ( defined($rtime)
        and defined($rsize)
        and ( $ltime >= $rtime )
        and ( $lsize == $rsize ) )
    {
        warn "Getting file $path: not newer than local copy.\n" if $VERBOSE;
        return;
    }

    warn "Getting file $path\n" if $VERBOSE;
    $ftp->get($path) or ( warn $ftp->message, "\n" and return );
    chmod $mode, $path if $mode;
}

On some of my servers, $rtime does not return a value. On others it does.
$rsize always returns a value, so I know that $path is correct. Anyone know
what I could check to troubleshoot this?

Thanks,

Asa


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org




More information about the spug-list mailing list