nsyed has asked for the wisdom of the Perl Monks concerning the following question:
Hello, fellow monks. I am still a learning monk so for give me for asking a very basic question. There are 2 parts of my code. First is to FTP a file from one server to another which works. Then compare the sizes of two files that is the source file and destination file. My file compare part of the code works only on the local files but on the network files I get file not found erroe. Please help. Thank you in advance.
############# FTP code that works #!/usr/bin/perl use strict; use File::stat qw(:FIELDS); use Net::FTP; my $s_user = "user1"; my $d_user = "user2"; my $s_passwd = my $d_passwd ="mypassword"; my $s_host = "some-server.com"; my $d_host = "some-server.com"; my $s_file = my $d_file = "test.txt"; my $s_ftp = Net::FTP->new($s_host) or die "$@"; my $d_ftp = Net::FTP->new($d_host) or die "$@"; $s_ftp->login($s_user, $s_passwd) or die $s_ftp->message; $d_ftp->login($d_user, $d_passwd) or die $d_ftp->message; my $s_dir = "/home/test/source"; my $d_dir = "/home/test/dest"; $s_ftp->cwd($s_dir) or die "Can't cwd to $s_dir\n"; $d_ftp->cwd($d_dir) or die "Can't cwd to $d_dir\n"; $s_ftp->binary() or die $s_ftp->message; $d_ftp->binary() or die $s_ftp->message; $s_ftp->pasv_xfer($s_file, $d_ftp, $d_file) or warn $s_ftp->ok ? $d_ftp->message : $s_ftp->message; $d_file = $s_file unless length $d_file; ##This will compare the size of two files and is not working $stat = stat($s_file) or die "Can't open File :$!"; if ($st_size & $st_mtime) { $size1 = $st_size; $mtime1 = $st_mtime; } $stat = stat($d_file) or die "Can't open File opened :$!"; if ($st_size & $st_mtime) { $size2 = $st_size; $mtime2 = $st_mtime; } if ($size1 == $size2) { print "File size matches.\n"; print ("Sourfile and Destination File sizes are :", $size1 ," ", $size2 , "\n"); }else{ print "Source file and Destination file have different sizes!\n"; print ("Sourfile and estination File sizes are :", $size1 ," ", $size2 , "\n"); } $s_ftp->quit; $d_ftp->quit;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: comparing files after FTP
by demerphq (Chancellor) on Oct 15, 2003 at 23:41 UTC | |
by nsyed (Novice) on Oct 16, 2003 at 01:42 UTC | |
Re: comparing files after FTP
by vek (Prior) on Oct 15, 2003 at 23:16 UTC | |
by nsyed (Novice) on Oct 16, 2003 at 13:26 UTC | |
by vek (Prior) on Oct 16, 2003 at 14:36 UTC | |
by nsyed (Novice) on Oct 17, 2003 at 15:36 UTC | |
Re: comparing files after FTP
by mandog (Curate) on Oct 15, 2003 at 22:38 UTC |
Back to
Seekers of Perl Wisdom