Gossamer Forum
Home : General : Perl Programming :

howto compare size of two files ?

Quote Reply
howto compare size of two files ?
hi

I have a serious problem with one script.
2 files ( AA1000020 and BB1000024 )
will be renamed ( to CC00000010 and DD000000011 ) according to a INFO file
and sent via ftp,
first the first one file and 5 minutes later the second one.

info file looks:

----------------------------------
AB1000020 CC00000010

BB1000024 DD000000011
----------------------------------

I cannot send the second file without the first one.
I have to be 100% sure, that the first one one file was completely transferred.

how to change this script, after first file was sent,
to compare the size of the first file ( CC00000010 )
locally at /var/ftp/files and on the ftp server
and only then send the second file ?

#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
use Net::FTP;
use Net::Netrc;

# change directory
chdir "/var/ftp/files" or die "/var/ftp/files: $!\n";

# DO NOT transfer without info file
-f "/home/ftp/files/info" or die "info file is missing\n";

open(FILE, "<info>");
while (<FILE> ) {
s/\W*$//;
next if (!$_);
/^(.+?) \s+ (.+?)$/x;

my ($old, $new) = ($1, $2);
rename $old, $new; # rename files

# ftp transfer

my $server = "X.X.X.X";
my $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3);
$ftp or die "$server: cannot connect: $@";
# If you don't use ~/.netrc
$ftp->login ('anonymous', 'test@domain.com') or
die "$_: cannot logon: " . $ftp->message;

# Put files to the ftp server
$ftp->put ($2) or
die "$server: cannot put $2: " . $ftp->message;

sleep ( 5 * 60 )

}


kind regards
ccc

Last edited by:

ccc: Feb 28, 2004, 3:32 PM
Quote Reply
Re: [ccc] howto compare size of two files ? In reply to
Hello ccc, How about thinking in reverse.

You need to send 2 files or not at all, is how I understand your question.

my silly solution :

1. tar or gzip the 2 files first. [ could be a crontab job or perl task ]
2. then just send the tar or gz file via net ftp.
3. a process can untar or unzip on the other side.

If you get the tar or gzip file then you should have both or not at all.

Does this make sence ?

thanks cornball
Quote Reply
Re: [cornball] howto compare size of two files ? In reply to
hi cornball

I can't do that.
on other site is a windows machine.
I send from linux to windows.
This procedure is a little bit complicated and
I must send these files SEPARATELY.

greetings
ccc
Quote Reply
Re: [ccc] howto compare size of two files ? In reply to
Hello ccc,

I do not understand what you are trying to do but my next thoughts might be :


If file A is not large in size :

1. Net::FTP Send file A from linux to windows.

2. Net::FTP Get file A from windows to linux with new linux local name.

3. compare files on linux old name with new name.

-- File A sent and File A_temp Get should compare equal on linux for size and content.

4. If old name A == new name A_temp send file B


does this make sence ?

thanks cornball

Linux file sizes and windows file sizes may differ.
Windows cluster size and Fat 12/16/32/NTFS versions may give different sizes
for the same file. So dir and ls may not be positive attributes.
Quote Reply
Re: [cornball] howto compare size of two files ? In reply to
hi cornball

yes, this make sence,
but can you post the perl code, please
I'm not a perl programmer.

kind regards
ccc

Quote Reply
Re: [ccc] howto compare size of two files ? In reply to
Hello ccc, It may be also solved with better code.

See : http://perlmonks.org/index.pl?node_id=317408

They use eval to test if a file was retrieved but this may also work with put.

thanks cornball