While you are binmoding the ftp transfer it doesnt look like you are binmoding the file you read in. On Win2 this means that first ^Z encountered in the file ends the file, it also means that perl performs CRLF type conversions before the data is seen by your code. This of course means the MD5 code on both platforms are actually looking at different data. (Printing out the length of the data read would have shown this immediately.) The answer of course is that if you are interested in byte level contents of a file (which you are) then you MUST binmode the file first irrespective of the OS.
Note that the common folk-story about not needing to binmode files on unix is not correct in the modern days of utf8 and wide characters. If you need the raw contents of a file you should binmode it regardless of operating system as the encoding could change etc.
With binmode
D:\>perl -le "use Digest::MD5 ('md5_base64'); local $/; open my $fh,sh +ift or die $!; binmode $fh if shift; $file=<$fh>; print qq(Bytes: ),l +ength($file),qq( ),md5_base64($file); " E:\Perl\bin\perl.exe 1 Bytes: 20540 vzpQPjhNDRjGpJccEa4iMw
Without binmode
D:\>perl -le "use Digest::MD5 ('md5_base64'); local $/; open my $fh,sh +ift or die $!; binmode $fh if shift; $file=<$fh>; print qq(Bytes: ),l +ength($file),qq( ),md5_base64($file); " E:\Perl\bin\perl.exe Bytes: 8295 ZFaA5qHXAClj0d1czg6hQA
PS: i surmise that the gzip files have some logic built in that makes them avoid special characters like ^Z and \0 and CRLF to avoid this type of issue in the first place. I have no idea if this is correct.
In reply to Re: md5 sum different on windows and unix for win.exe files !!?
by demerphq
in thread md5 sum different on windows and unix for win.exe files !!?
by Random_Walk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |