pb download file on internet site

W

Winston75

hi,

no errors in my code, but not downloaded file on my disk .
getstore ($url, $filename) not working? i don't know, any ideas?

thanks,



#!/usr/bin/perl -w

use strict;
use warnings;
use LWP::UserAgent;
use LWP::Simple;
use HTML::SimpleLinkExtor;

my $base='https://username:[email protected]/index.html';
my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.73 [en] (X11; I;
Linux 2.2.16 i686; Nav)' );
my $req = HTTP::Request->new( GET => "${base}" );
my $res = $ua->request($req);
die $res->status_line
if not $res->is_success;

my $extractor = HTML::SimpleLinkExtor->new(); $extractor->parse($res-
content);

my @allLinks = $extractor->links;

for (@allLinks)
{
if (/zip/)
{
my $url="https://www.mysite.com/index.html/$_";
my (@tab)=split / \ / /;
my $fileName = $tab[1];

print "downloading $fileName....";
getstore($url, $fileName);
print "Done !\n";
}
}
exit(0);
 
P

Peter Makholm

Winston75 said:
no errors in my code, but not downloaded file on my disk .
getstore ($url, $filename) not working? i don't know, any ideas?

You don't test the return value of getstore(). This might tell you
something useful.

//Makholm
 
W

Winston75

You don't test the return value of getstore(). This might tell you
something useful.

//Makholm

thanks, sorry i'm newbie in perl, how to test return value of
getstore()??

print result?
 
W

Winston75

thanks, sorry i'm newbie in perl, how to test return value of
getstore()??

print result?

Ok :

getstore ($url, $filename);
print $!;

Result --> bade file descriptor !!

zip are correct and not corrupt!
 
P

Peter Makholm

Winston75 said:
thanks, sorry i'm newbie in perl, how to test return value of
getstore()??

The documentation will tell you that the return value of getstore() is
the HTTP response code. Reading a bit more of the LWP::Simple
documentation will show that the module also exports two functions
is_success and is_error. Use one of these functions.


my $rc = getstore($url, $filename);
if ( is_success( $rc ) {
print "Done!\n";
} else {
print "Failed with response code $rc\n";
}

For an even better error message you can use the status_message()
function from the HTTP::Status module.

(I suspect that you get an 401 response code which is the
code for 'Unauthorized access')

//Makholm
 
J

Joost Diepenmaat

Winston75 said:
Ok :

getstore ($url, $filename);
print $!;

Result --> bade file descriptor !!

The value of $! doesn't mean anything unless you know that the last IO
operation that occorred resulted in an error. You don't know that here.

Looking at the docs for LWP::Simple, seems you need something like this:

my $rc = getstore($url,$filename);
if (is_error($rc)) {
die "Some error occurred: $rc";
}
 
P

Peter Makholm

Winston75 said:
getstore ($url, $filename);
print $!;

Only assume that $! is relevant if the documentation says so, and even
when the documentation says that it is relevant it is almost always if
the called function signals an error in some way.

//Makholm
 
W

Winston75

Only assume that $! is relevant if the documentation says so, and even
when the documentation says that it is relevant it is almost always if
the called function signals an error in some way.

//Makholm


Ok thanks, my results :

downloading file1.zip....Failed with response code 404
downloading file2.zip....Failed with response code 404
downloading file3.zip....Failed with response code 404
 
W

Winston75

"Quoth the server, 404.
That file, it don't exist no more."

--
             Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -


So i don't understand how to download this file? my script is correct.
fyi, if i run this script with the direct link, i have an error 401 :
unauthorised access :

#!/usr/bin/perl

use LWP::Simple;
use strict;
use warnings;
use LWP::UserAgent;
use LWP::Simple;
use HTML::SimpleLinkExtor;

my $base='https://username:[email protected]/index.shtml';
my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.73 [en] (X11; I;
Linux 2.2.16 i686; Nav)' );
my $req = HTTP::Request->new( GET => "${base}" );
my $res = $ua->request($req);
die $res->status_line
if not $res->is_success;


#-- fetch the zip and save it
my $status = getstore("https://www.mysite/index.shtml",
"MyZipFile.zip");

if ( is_success($status) )
{
print "file downloaded correctly\n";
}
else
{
print "error downloading file: $status\n";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,034
Messages
2,570,356
Members
47,002
Latest member
RobertoLip

Latest Threads

Top