rmahin has asked for the wisdom of the Perl Monks concerning the following question:
Hey monks,
Hopefully this is an easy one. I have a program that transfers files, and checks SHA values to ensure success. However I am now trying to transfer binary files, like tar/zip files, and the sha values are not matching up when i go from windows to unix, and unix to windows. This occurs regardless of if I use standard ftp, or my code to transfer the files.
Here is the code I'm usingAny help you can offer is most appreciated!use strict; use warnings; use Digest::SHA; my $file = shift; print calculateSHA($file); print "\n"; sub calculateSHA{ my $data = shift; my $val = 0; eval{ my $sha1 = Digest::SHA->new(256); #supposed to be portable and os independant? not working. $sha1->addfile($data, "p"); $val = $sha1->hexdigest; }; if($@){ print "An error occurred calculating the SHA-Value. Cannot ver +ify integrity of file\n$@\n"; } return $val; }
RESOLVED: I'm really not sure what did it, but eventually using the $sha1->addfile($data, "p"); made everything work...A little confused as to why it wasn't when I first tried, must have missed something...but anyways, everything is working now, thank you all for the help
|
---|
Back to
Seekers of Perl Wisdom