From: Winston75 on
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(a)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);
From: Peter Makholm on
Winston75 <baptiste.fevre(a)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

From: Winston75 on
On 24 avr, 17:47, Peter Makholm <pe...(a)makholm.net> wrote:
> Winston75 <baptiste.fe...(a)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

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

print result?
From: Winston75 on
On 24 avr, 17:55, Winston75 <baptiste.fe...(a)gmail.com> wrote:
> On 24 avr, 17:47, Peter Makholm <pe...(a)makholm.net> wrote:
>
> > Winston75 <baptiste.fe...(a)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
>
> 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!
From: Peter Makholm on
Winston75 <baptiste.fevre(a)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