Re: Remote directory <-> local directory comparison


Subject: Re: Remote directory <-> local directory comparison
From: Peter Q. Olsson (olsson@koyukuk.at.uaa.alaska.edu)
Date: Wed Dec 18 2002 - 15:03:15 AKST


Tim-

Here is a way to do basically what you want. You WILL need the Net::FTP
module, which you can get from the CPAN archives. Think if may come as a part of
a bundle, (maybe libnet?). If you do much w/ automated ftp transfers it is worth
the time to get.

I havbe tested the ftp part, it works. the file list comparisons I did not test
directly, but it should be close. You also "use strict" here (hence the my's and
our's) , but you use strict anyway, right?

At any rate, hack away:

###########
#!/usr/local/bin/perl

use Net::FTP;
use strict;
our $AUTOFLUSH = 1; # flush each line as it is written

my $VERBOSE = 1; # extra prints optional, set to 0 for silent running

my $ftp = Net::FTP->new("ftp.redhat.com");
$ftp->login("anonymous",'me@here.there');
$ftp->cwd("/pub/contrib/noarch/SRPMS"); # set current working dir (cd)

# get a list
my @remote_list = $ftp->ls;

$VERBOSE and print join "\n", @remote_list;

my %remote_size;

#iterate over list, finding each file's size
foreach my $fid (@remote_list)
{
  $remote_size{$fid} = $ftp->size($fid);
  $VERBOSE and print "$fid, $remote_size{$fid}\n";
}

## now, for the local directory

opendir DIR,"local_dir";
my @local_list =readdir DIR;

## find files locally that also exist remotely
foreach my $fid (@local_list)
{
  exists $remote_size{$fid} ?
         print "found $fid on remote site\n" :
         print "did not find $fid on remote site\n";
}

    __________________________________________________________________
   | |
   | Dr. Peter Q. Olsson, |
   | Chief Scientist, Alaska Experimental Forecast Facility |
   | University of Alaska Anchorage |
   | 2811 Merrill Field Drive |
   | Anchorage, AK 99501 |
   | voice: (907) 264-7449 |
   | fax : (907) 264-7444 |
   | olsson@aeff.at.uaa.alaska.edu |
   |__________________________________________________________________|

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.



This archive was generated by hypermail 2a23 : Wed Dec 18 2002 - 15:05:46 AKST