Download manager
am 17.09.2004 20:06:10 von orasnita
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
Re: Download manager - problem solved
am 17.09.2004 23:18:10 von orasnita
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"
To:
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
Re: Download manager - problem solved
am 18.09.2004 07:35:44 von gisle
"Octavian Rasnita" 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
Re: Download manager - problem solved
am 18.09.2004 08:52:47 von orasnita
From: "Gisle Aas"
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