Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

need help downloading a file

by Todd Chester (Scribe)
on Jul 22, 2017 at 06:28 UTC ( [id://1195763]=perlquestion: print w/replies, xml ) Need Help??

Todd Chester has asked for the wisdom of the Perl Monks concerning the following question:

Dear Perl Monks,

I am trying to get this curl command to work with perl5:

curl --header 'Host: download.fosshub.com' http://www.fosshub.com/HWiN +FO.html/hw64_554.exe -o eraseme

But no joy. Here is my test code.

http://vpaste.net/cco4p

What am I doing wrong?

Replies are listed 'Best First'.
Re: need help downloading a file
by Corion (Patriarch) on Jul 22, 2017 at 08:29 UTC

    Please don't paste links to offsite code.

    Put your code here, in between <code>...</code> tags so that everybody can see it.

    What exactly is the problem with your code? Does it download the wrong content? Does it get an unexpected server response?

    The idea behind automating HTTP downloads is to ideally send exactly the headers that the working example is sending. See the curl documentation to make Curl output the headers it sends and then LWP::ConsoleLogger to see what LWP sends. Compare the two and adjust your program until they send the same data.

      I used vtext.net as that is what the developers like over on the chat channels. But if you are willing to help me, I will paint it green if you want! I do have a difficult time with the format on this forum, but I use it anyway because you guys are scary good at what you do.
Re: need help downloading a file
by huck (Prior) on Jul 22, 2017 at 08:43 UTC

    if ( ! $response->is_success ) { use Data::Dumper; print Dumper($response); ... }
    Gives (in part)
    ... The owner of this website (download.fosshub.com) has banned your acces +s based on your browser\'s signature (38250110cd8b5c57-ua22). ...

    sub DownloadWebFile { # Download the $Url's file my $IAm = ( caller(0) )[3]; # Incoming: my $Url = $_[0]; my $Timeout = $_[1]; my $Cookies = $_[2]; # 'oraclelicense=accept-securebackup-cookie' my $Referer = $_[3]; # "http://usa.kaspersky.com/windows10"; my $Host = $_[4]; # "download.fosshub.com"; my $FileName = $_[5]; # File name and path to save the file to my $Caller = "$_[6]" . "$IAm"; # Outgoing: my $PageStatus = \$_[7]; $$PageStatus = UPDATE; # 2 = good download my $ua; $ua = LWP::UserAgent->new; $ua->timeout ( MaxTime2 ); $ua->show_progress ( 1 ); # 0 = do not show; 1 = show my $req = new HTTP::Request (GET => $Url ,HTTP::Headers->new( 'Referer' => + 'https://www.fosshub.com/HWiNFO.html', 'User-Agent' => + 'Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Firefox/52.0' ) ); my $response = $ua->request ($req); if ( ! $response->is_success ) { $$PageStatus = DOWNLOAD_FAIL; use Data::Dumper; print Dumper($response); print STDERR " ERROR ${Caller}.GetWebPage: unable to read ", $Url, "\n"; print STDERR $response->status_line; return ""; } }
    Gives ** GET https://www.fosshub.com/HWiNFO.html/hw64_554.exe ==> 200 OK (4s)

      When you access www.fosshub.com or attempt to retrieve content or file +s that we host on our site or any other 3rd party service paid by us +we do not allow the following (exceptions apply - read below): - automate the download process using various tools or code (regardles +s of its type: open source or closed source) that can disrupt our ser +vice. - attempt to download from FossHub infrastructure using a script, prog +ram or any other similar tool without our approval

      https://www.fosshub.com/tos.html

        Didnt see that when i looked at https://www.fosshub.com/HWiNFO.html

        Exceptions
        - If you represent a non-profit organization focused on education, health or any other worthy cause.

        Well i certainly am non-profit and this was focused on education :)

        Is it binding if they dont force you to accept first?

          A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1195763]
Approved by Laurent_R
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-20 06:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found