Hi y'all!
I'm new at perl, and I'm trying to automate a file fetch.
I have this url (in this example called 'https://GetMyFile'), which, when I paste it into a browser, gives me the pop-up "File Download" - Do you want to open or save this file?.. And clicking 'save' gives me the file I want.
I would like to achieve the same result automatically, without having to paste the url into a browser and click 'save' a specify where to save my file.
So, here's my first attempt:
---------------------------------------------------------------------
--------------------------------------------------------------------
The thing is, I don't get the "oops" printout, instead myFile.zip is downloaded to the correct location, but this file is corrupted. It seems it doesn't get downloaded entirely since when I download it manually it's much bigger.
Here are some debug printouts I get
Any help or suggestions as to why I don't get the entire file (?) would be greatly appreciated!
Cheers
I'm new at perl, and I'm trying to automate a file fetch.
I have this url (in this example called 'https://GetMyFile'), which, when I paste it into a browser, gives me the pop-up "File Download" - Do you want to open or save this file?.. And clicking 'save' gives me the file I want.
I would like to achieve the same result automatically, without having to paste the url into a browser and click 'save' a specify where to save my file.
So, here's my first attempt:
---------------------------------------------------------------------
Code:
use strict; use WWW::Mechanize; use LWP::Debug qw(+); my $ua = new LWP::UserAgent; $ua->proxy([qw( https http )], "myProxyAddress"); my $url = "https://GetMyFile"; my $mech = WWW::Mechanize->new(); print "Fetching $url"; $mech->get( $url, ':content_file' => 'C:\Tmp\myFile.zip' ); die "Ooops, that didn't work: ", $mech->response->status_line unless $mech->success;
The thing is, I don't get the "oops" printout, instead myFile.zip is downloaded to the correct location, but this file is corrupted. It seems it doesn't get downloaded entirely since when I download it manually it's much bigger.
Here are some debug printouts I get
Code:
LWP::UserAgent::new: () LWP::UserAgent::proxy: ARRAY(someHexNumber) myProxyAddress LWP::UserAgent::proxy: https myProxyAddress LWP::UserAgent::proxy: http myProxyAddress LWP::UserAgent::new: () LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking GetMyFile for cookies LWP::UserAgent::send_request: GET [url]https://GetMyFile[/url] LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 336 bytes LWP::UserAgent::request: Simple response: Found LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking GetMyFile for cookies LWP::UserAgent::send_request: GET [url]https://GetMyFile[/url] LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 439 bytes LWP::Protocol::collect: read 176 bytes LWP::UserAgent::request: Simple response: Found ... Then these printouts are repeated ... LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 869 bytes LWP::Protocol::collect: read 4096 bytes LWP::Protocol::collect: read 4096 bytes LWP::Protocol::collect: read 2395 bytes LWP::UserAgent::request: Simple response: OK Fetching [url]https://GetMyFile[/url]
Cheers
Comment