Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: (http and ftp clients)

I would like to retrieve html documents from an .htaccess/.htpasswd protected directory. Can I do this with perl?

Originally posted as a Categorized Question.

  • Comment on How do I retrieve .htpasswd protected html documents?

Replies are listed 'Best First'.
Re: How do I retrieve .htpasswd protected html documents?
by KM (Priest) on Oct 12, 2000 at 21:00 UTC
    Yes, you sure can. Use LWP::UserAgent:

    use LWP::UserAgent; my $ua = new LWP::UserAgent; my $req = new HTTP::Request 'GET', 'http://www.you.com/dir'; $req->authorization_basic('userid', 'password'); my $result = $ua->request($req)->as_string;

    Read the POD for the module, as well as lwp-cook for other options/uses.

    Cheers,
    KM

Re: How do I retrieve .htpasswd protected html documents?
by tilly (Archbishop) on Oct 12, 2000 at 23:14 UTC
    Look at Put name and password in URLs. That trick should work with custom Perl scripts, utilities like lwp-request, and even programs in other languages. (I use it to visit ftp sites with a browser.)