Download manager

Hello,

I want to create a module that will have a method that should work like a
download manager.
It will be able to automaticly resume downloads, meaning that if a local
file with a given name exists, it will start downloading the remote file
skipping the number of bytes that file contains, and adding the rest of the
remote file to the local one.

I have seen that the recommended way for saving a file using LWP is to use
something like:

$ua->get($url, ":content_file" => $file);

But I would like to know if there is a more flexible way that allow setting
some headers (like the referer, and setting the Range of bytes that will be
downloaded, eventually setting and getting cookies, etc).
It would be very good if that more flexible way wouldn't require storing the
content of that file into a variable, but saving it directly into a file.

What methods do you suggest me to try?

Thank you.

Teddy
orasnita [ Fr, 17 September 2004 20:06 ] [ ID #18712 ]

Re: Download manager - problem solved

Hi,

I have found how to insert HTTP headers in the line:

$ua->get($url, ":content_file" => $file);

....But I still can't find how to get and send cookies in other way than
trying to manually add the headers for Cookies.

Thanks.

Teddy

----- Original Message -----
From: "Octavian Rasnita" <orasnita [at] fcc.ro>
To: <libwww [at] perl.org>
Sent: Friday, September 17, 2004 9:06 PM
Subject: Download manager


Hello,

I want to create a module that will have a method that should work like a
download manager.
It will be able to automaticly resume downloads, meaning that if a local
file with a given name exists, it will start downloading the remote file
skipping the number of bytes that file contains, and adding the rest of the
remote file to the local one.

I have seen that the recommended way for saving a file using LWP is to use
something like:

$ua->get($url, ":content_file" => $file);

But I would like to know if there is a more flexible way that allow setting
some headers (like the referer, and setting the Range of bytes that will be
orasnita [ Fr, 17 September 2004 23:18 ] [ ID #18713 ]

Re: Download manager - problem solved

"Octavian Rasnita" <orasnita [at] fcc.ro> writes:

> I have found how to insert HTTP headers in the line:
>
> $ua->get($url, ":content_file" => $file);
>
> ...But I still can't find how to get and send cookies in other way than
> trying to manually add the headers for Cookies.

Just enable the cookie jar, with $ua->cookie_jar({}), and LWP will
manage the cookies for you.

Regards,
Gisle
gisle [ Sa, 18 September 2004 07:35 ] [ ID #18714 ]

Re: Download manager - problem solved

From: "Gisle Aas" <gisle [at] ActiveState.com>

Just enable the cookie jar, with $ua->cookie_jar({}), and LWP will
manage the cookies for you.
--

Ok, I have tried that, but it still doesn't work as I want. I would like to
do something like the following code does in case the $request and $response
vars are initialised:

#Send the cookies to the site:
if (-e $cookies_file) {
$cookie_jar -> load($cookies_file);
$cookie_jar->add_cookie_header($request);
}

#Get the cookies
if($cookies_file) {
$cookie_jar->extract_cookies($response);
$cookie_jar -> save($cookies_file);
}

If I just use the following code, this doesn't save a cookies.txt file:

my $cookies_file = "cookies.txt";
$cookie_jar = HTTP::Cookies -> new(3, $cookies_file, autosave => 1,
ignore_discard => 1);
$ua->cookie_jar({});

Thank you.

Teddy
orasnita [ Sa, 18 September 2004 08:52 ] [ ID #18715 ]
Perl » perl.libwww » Download manager

Vorheriges Thema: Removing url encoding from XML POST requests
Nächstes Thema: LWP download problem , Please Help!