Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot

Links

XODOX
Impressum

#1: pb download file on internet site

Posted on 2008-04-24 17:40:52 by 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);

Report this message

#2: Re: pb download file on internet site

Posted on 2008-04-24 17:47:14 by Peter Makholm

Winston75 <baptiste.fevre@gmail.com> 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

Report this message

#3: Re: pb download file on internet site

Posted on 2008-04-24 17:55:35 by Winston75

On 24 avr, 17:47, Peter Makholm <pe...@makholm.net> wrote:
> Winston75 <baptiste.fe...@gmail.com> 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?

Report this message

#4: Re: pb download file on internet site

Posted on 2008-04-24 18:03:47 by Winston75

On 24 avr, 17:55, Winston75 <baptiste.fe...@gmail.com> wrote:
> On 24 avr, 17:47, Peter Makholm <pe...@makholm.net> wrote:
>
> > Winston75 <baptiste.fe...@gmail.com> 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!

Report this message

#5: Re: pb download file on internet site

Posted on 2008-04-24 18:08:07 by Peter Makholm

Winston75 <baptiste.fevre@gmail.com> 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

Report this message

#6: Re: pb download file on internet site

Posted on 2008-04-24 18:09:35 by Joost Diepenmaat

Winston75 <baptiste.fevre@gmail.com> 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/

Report this message

#7: Re: pb download file on internet site

Posted on 2008-04-24 18:09:39 by Peter Makholm

Winston75 <baptiste.fevre@gmail.com> 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

Report this message

#8: Re: pb download file on internet site

Posted on 2008-04-24 18:24:59 by Winston75

On 24 avr, 18:09, Peter Makholm <pe...@makholm.net> wrote:
> Winston75 <baptiste.fe...@gmail.com> 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

Report this message

#9: Re: pb download file on internet site

Posted on 2008-04-24 19:30:24 by RedGrittyBrick

Winston75 wrote:
> On 24 avr, 18:09, Peter Makholm <pe...@makholm.net> wrote:
>> Winston75 <baptiste.fe...@gmail.com> 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

Report this message

#10: Re: pb download file on internet site

Posted on 2008-04-24 22:26:49 by Chris Mattern

On 2008-04-24, Winston75 <baptiste.fevre@gmail.com> wrote:
> On 24 avr, 18:09, Peter Makholm <pe...@makholm.net> wrote:
>> Winston75 <baptiste.fe...@gmail.com> 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

Report this message