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.

---
demerphq


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

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.