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;

In reply to comparing files after FTP by nsyed

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.