sravan2000 has asked for the wisdom of the Perl Monks concerning the following question:

I was trying to compare the file size after FTP'ing it to the remote server. But I'm getting a different size, if I use $ftp->size($rem_file) on the remote server, and I'm getting the correct size(in bytes) on my local machine using $file = -s $local_file. I don't understand what could be the reason that the size function is showing a different size for a remote file. I would appreciate if you could help me out. Thanx.

Replies are listed 'Best First'.
Re: File size on the Remote server
by no_slogan (Deacon) on Jun 05, 2001 at 23:16 UTC
    Did you do $ftp->binary()?
      No. it's in Ascii format and stream mode. Do you think this could be the problem ?? Thanx
      I did changed to binary. Now it's been working and I'm getting the correct file size. But my question is, when I'm FTP'ing to the same OS remote server (HP) and the file is an ascii type, is there any kind of impact ??? thanx
        Glad it's working for you now. What you need to understand about ascii type is that it changes all line ends to carriage-return-line-feeds when they go "over the wire" from one machine to the other. Even if the two machines have the same end of line conventions, your file gets chewed on twice (once converting to CRLFs, and again when converting back), and in some cases that might leave some tooth marks. Some ftp clients will detect that situation and automatically switch to binary mode... others won't.
Re: File size on the Remote server
by TGI (Parson) on Jun 05, 2001 at 23:35 UTC

    Some filesystems can affect the size of a file. (HFS comes to mind.) It could be file system overhead.


    TGI says moo

      Is there a way to handle this ??? All I need is to check weather the file that was transferred was succesful (there are cases where the file transferred was not complete), otherwise we need to run the script again and that's a real pain for me. And we don't have the delete permissions on the remote server. The same command (size $rem_file) works fine at FTP prompt. Please advice me to get the file size on the remote server. Thanx
Re: File size on the Remote server
by traveler (Parson) on Jun 06, 2001 at 00:08 UTC
    I suspect that one system ends lines in <CRLF> and the other ends them in <LF> (e.g. one is some UNIX variant and one is a Microsoft OS). ASCII transfer mode will generally change the line endings as necessary to deal with this.

    You can check if this is the case by seeing if

    $lines_in_file + $size_of_smaller_file == $lines_in_larger_file
Re: File size on the Remote server
by jorg (Friar) on Jun 06, 2001 at 00:56 UTC