The piece of code belows downloads a file and compares it with itself using the SHA algorithm in order to prove the download was correct. I tested it with a number of binary files that were available on my Windows box and always worked right.
The result is something like:use strict; use LWP::UserAgent; use Digest::SHA1; my $srcfile = "c:/...../cab/WBCust.CAB"; my $tempdl = "temp.tmp"; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(GET => 'http://127.0.0.1/...../cab/WBCust +.CAB'); my $r = $ua->request($req)->content; open F, ">$tempdl" or die "$! $tempdl"; binmode F; print F $r; close F; computeSHA( $srcfile ); computeSHA( $tempdl ); unlink $tempdl; exit; sub computeSHA() { my ($srcfile) = @_; my $sh_pre = Digest::SHA1->new; open S1, $srcfile or die "$! $srcfile"; $sh_pre->addfile(*S1); close S1; print "$srcfile:\n " . $sh_pre->hexdigest . "\n"; }
c:/...../cab/WBCust.CAB: 3816f34e861b6268c716b9f06091dee0d580f2cb temp.tmp: 3816f34e861b6268c716b9f06091dee0d580f2cb
In reply to Re: Download file over HTTP
by l3nz
in thread Download file over HTTP
by chaskins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |