pb download file on internet site

pb download file on internet site

am 24.04.2008 17:40:52 von 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:password@www.mysite.com/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);

Re: pb download file on internet site

am 24.04.2008 17:47:14 von Peter Makholm

Winston75 writes:

> 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

Re: pb download file on internet site

am 24.04.2008 17:55:35 von Winston75

On 24 avr, 17:47, Peter Makholm wrote:
> Winston75 writes:
> > no errors in my code, but not downloaded file =A0on my disk .
> > getstore ($url, $filename) not working? =A0i don't know, any ideas?
>
> 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?

Re: pb download file on internet site

am 24.04.2008 18:03:47 von Winston75

On 24 avr, 17:55, Winston75 wrote:
> On 24 avr, 17:47, Peter Makholm wrote:
>
> > Winston75 writes:
> > > no errors in my code, but not downloaded file =A0on my disk .
> > > getstore ($url, $filename) not working? =A0i don't know, any ideas?
>
> > 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?

Ok :

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

Result --> bade file descriptor !!

zip are correct and not corrupt!

Re: pb download file on internet site

am 24.04.2008 18:08:07 von Peter Makholm

Winston75 writes:

>> > 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.
>
> 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

Re: pb download file on internet site

am 24.04.2008 18:09:35 von Joost Diepenmaat

Winston75 writes:

> 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";
}


--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Re: pb download file on internet site

am 24.04.2008 18:09:39 von Peter Makholm

Winston75 writes:

> 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

Re: pb download file on internet site

am 24.04.2008 18:24:59 von Winston75

On 24 avr, 18:09, Peter Makholm wrote:
> Winston75 writes:
> > 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


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

Re: pb download file on internet site

am 24.04.2008 19:30:24 von RedGrittyBrick

Winston75 wrote:
> On 24 avr, 18:09, Peter Makholm wrote:
>> Winston75 writes:
>>> 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
>
>
> 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

404 means the URL is incorrect - there's no page with that path.

I'd change the print statement from
print "downloading $fileName....";
to
print "downloading $fileName from '$url' ....";

I expect that will identify the problem.

--
RGB

Re: pb download file on internet site

am 24.04.2008 22:26:49 von Chris Mattern

On 2008-04-24, Winston75 wrote:
> On 24 avr, 18:09, Peter Makholm wrote:
>> Winston75 writes:
>> > 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
>
>
> 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

"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