pb download file on internet site

Discussion in 'Perl Misc' started by Winston75, Apr 24, 2008.

  1. Winston75

    Winston75 Guest

    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:p/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);
     
    Winston75, Apr 24, 2008
    #1
    1. Advertising

  2. 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
     
    Peter Makholm, Apr 24, 2008
    #2
    1. Advertising

  3. Winston75

    Winston75 Guest

    On 24 avr, 17:47, Peter Makholm <> wrote:
    > 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


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

    print result?
     
    Winston75, Apr 24, 2008
    #3
  4. Winston75

    Winston75 Guest

    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  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!
     
    Winston75, Apr 24, 2008
    #4
  5. 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
     
    Peter Makholm, Apr 24, 2008
    #5
  6. 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/
     
    Joost Diepenmaat, Apr 24, 2008
    #6
  7. 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
     
    Peter Makholm, Apr 24, 2008
    #7
  8. Winston75

    Winston75 Guest

    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
     
    Winston75, Apr 24, 2008
    #8
  9. Winston75

    Winston75 Guest

    On 24 avr, 22:26, Chris Mattern <> wrote:
    > 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- 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:p/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";
    }
     
    Winston75, Apr 25, 2008
    #9
  10. Winston75 <> writes:

    > my $base='https://username:p/index.shtml';
    > my $req = HTTP::Request->new( GET => "${base}" );
    > my $res = $ua->request($req);


    Here you request a page while authentificating with an username and a
    password.

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


    Here you request the same page with no authentification.

    //Makholm
     
    Peter Makholm, Apr 25, 2008
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cmay
    Replies:
    0
    Views:
    1,182
  2. Roger Withnell

    IE cannot find internet site to download BLOB

    Roger Withnell, Jul 10, 2003, in forum: ASP General
    Replies:
    0
    Views:
    121
    Roger Withnell
    Jul 10, 2003
  3. Roger Withnell

    IE cannot find internet site to download blob

    Roger Withnell, Jul 10, 2003, in forum: ASP General
    Replies:
    7
    Views:
    145
    Larry Gillstrom
    Jul 13, 2003
  4. Roger Withnell

    IE cannot find internet site to download BLOB

    Roger Withnell, Jul 11, 2003, in forum: ASP General
    Replies:
    0
    Views:
    119
    Roger Withnell
    Jul 11, 2003
  5. John Smith
    Replies:
    1
    Views:
    174
    Evertjan.
    Mar 12, 2005
Loading...

Share This Page