anchylo has asked for the wisdom of the Perl Monks concerning the following question:
Hello I am having difficulty downloading a file (and am tired of downloading them directly...
<code>
#!/usr/bin/perl
use LWP;
my $url = 'https://192.168.1.1/cgi-bin/get-sae-log.cgi?host=thingy&date=20090703'; # Yes, HTTPS!
my $browser = LWP::UserAgent->new;
my $response = $browser->get($url);
die "Error at $url\n ", $response->status_line, "\n Aborting"
unless $response->is_success;
print "Whee, it worked! I got that ",
$response->content_type, " document!\n";
<\code>
results with:
C:\dhcp.logs\bc>xplore_lwp.pl
Whee, it worked! I got that application/x-bzip2 document!
ok, so i can see the document, but am at a loss as to how to name and download the file.
I have tried lwp-download, but got massive errors...
any help appreciated.
Re: LWP HTTPS and a sore head
by Anonymous Monk on Jul 15, 2009 at 20:31 UTC
|
I have tried lwp-download, but got massive errors...
What errors?
LWP::Simple
use LWP::Simple ;
if (mirror("http://www.sn.no/", "foo") == RC_NOT_MODIFIED) {
...
}
| [reply] [d/l] |
|
If you afraid of pasting your errors here :)
try Mechanize.pm --> "http://search.cpan.org/~petdance/WWW-Mechanize-1.58/lib/WWW/Mechanize.pm"
| [reply] |
Re: LWP HTTPS and a sore head
by tokpela (Chaplain) on Jul 16, 2009 at 08:37 UTC
|
use strict;
use LWP::Simple;
my $url = 'https://192.168.1.1/cgi-bin/get-sae-log.cgi?host=thingy&da
+te=20090703';
my $file = 'document.bzip2';
my $rc = getstore($url, $file);
if (is_success($rc)) {
"Success - saved [$url] to [$file]\n";
} else {
"Error - [$rc] error in getting [$url]\n";
}
| [reply] [d/l] |
Re: LWP HTTPS and a sore head
by hnd (Scribe) on Jul 16, 2009 at 04:48 UTC
|
if you are on *nix then you can pipe your data into a file like
> (your program)>>(file name)
but delete the print statement before the actual output.....
=====================================================
i'am worst at what do best and for this gift i fell blessed... i found it hard it's hard to find well whatever NEVERMIND
| [reply] [d/l] |
Re: LWP HTTPS and a sore head
by hnd (Scribe) on Jul 16, 2009 at 04:48 UTC
|
if you are on *nix then you can redirect your data into a file like
> (your program)>>(file name)
but delete the print statement before the actual output.....
=====================================================
i'am worst at what do best and for this gift i fell blessed... i found it hard it's hard to find well whatever NEVERMIND
| [reply] [d/l] |
Re: LWP HTTPS and a sore head
by BaldManTom (Friar) on Jul 16, 2009 at 13:04 UTC
|
Hi anchylo,
I believe you've already "downloaded" the file, you just need to give it a filename and put it somewhere. Use any filename that makes sense to you:
# Following your original code snippet
my $filename = 'logfile.bz2';
open ( OF, '>', $filename ) || die "Can't open $filename locally";
print OF $response->content;
close OF
Note that you may need to binmode your filehandle before writing to it if your content isn't text. | [reply] [d/l] |
|
You may want to print $response->decoded_content to deal with the situation whereby the file is gzip encoded..
| [reply] [d/l] |
|