Validating the size of file transferred from ftp server to the local system

Validating the size of file transferred from ftp server to the local system.

File type: Text file/Flat file
Source System: Windows / Unix Systems
Target System is always: Unix
Mode of Transfer : ASCII

We have generic ftp shell script that transfers the files from different ftp servers.

Some time files are only getting transferred partially & doesn't show any errors.
An example scenario is given below.
Example Scenario:
Souce System: Unix
Source File's size: 4000 Kbytes.
Target System: Unix
Target File size: 2000 K bytes.
Reason for the difference in File size: As the target unix system is not having enough space, & the FTP utility doesn't treat this kind of scenario as an error, the final outcome of the script was successful.

We would like to handle this scenario with the addition of the logic to check the file sizes of the source & target system and decide the final outcome of the script. Please provide your thoughts/suggestions.

Options Tried:
We also tried one of the option that ftp log itself is capturing the file size while transferring. This size is not matching with actual file size got transferred to the local system due to difference in the OS of source and destination.

Ancient classic problem:

  • The cheapest thing is to put the size in the file name, unless this is dos. Then the recipient can check to see if it is right. On a good day, the recipient can tell it is no longer being written, like with fuser.
  • Send the length or better yet the cksum in a marker file, afterwards so it tells the recipient that the file is all sent.
  • The sending end could send to a temporary name or folder, then check the length, and finally rename/move the file to the right name, which intrinsically tells the recipient that it is valid.
  • Crude, lewd but secure: fetch the file back and compare it byte for byte. You might still need some token to tell the other end it is ready, like a rename/move or an ack file.

I don't work with ftp very often (except as a client fetching stuff from the internet), but doesn't ASCII transfer mode change a text file's contents and size when the systems involved use different line endings?

Regards,
Alister