Hi,

Here is a script I've made for downloading a file from a remote location, or
for downloading a list of files.

If you want to download a single file, you will need to use in the command
line something like:

perl script.pl http://site.com/file.zip
or if you want to specify the directory where to put the file:
perl script.pl http://site.com/file.zip directory

or if you want to download a list of files contained in a text file, with a
single link on each row of that file, use:
perl script.pl path_to_text_file
or
perl script.pl path_to_text_file directory

You should change the paths I've used in the script.

#!/usr/bin/perl -w

#This program downloads a file or a list of files from web in binary mode

use strict;
use LWP::UserAgent;

my $location = $ARGV[0];
my $save_dir;
if ($ARGV[1]) {
$save_dir = $ARGV[1];
} else {
if ($^O =~ /MSWin32/i) {
$save_dir = "f:/teddy/writable/download";
chdir("f:/teddy/writable");
mkdir("download") unless -e "f:/teddy/writable/download";
} else {
$save_dir = "/var/www/teddy/writable/download";
chdir("/var/www/teddy/writable");
mkdir("download") unless -e "/var/www/teddy/writable/download";
}
}

my $ua = LWP::UserAgent -> new(env_proxy => 0,
timeout => 50,
keep_alive => 1,
);

my ($file, %file);
if ($location =~ /^(http|ftp)/i) {
$file = $location;
$file =~ s/^.*\///;
$file{$location} = $file;
}
else {
open (IN, $location) or die "Can't read $location - $!";
while (<IN>) {
chomp;
$file = $_;
$file =~ s/^.*\///;
$file{$_} = $file;
}
close IN;
}

foreach my $f(keys %file) {
while (-e "$save_dir/$file{$f}") {
$file{$f} = '1' . $file{$f};
}

my $request = HTTP::Request -> new('GET', $f);
my $response = $ua -> request($request, "$save_dir/$file{$f}");
}


Teddy,
Teddy's Center: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]

----- Original Message -----
From: "Antonis Antoniou" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, February 11, 2003 6:49 PM
Subject: Download zip files automatically


Hi,

I would like to download from http://www.somewhere.com/zip/file.zip
through a script. Is there any module that I can do this?
This will help me download the zip files automaticaly.

Many Thanks
Antonis


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to