Click to See Complete Forum and Search --> : Help in PERL for file download using HTTP,INET


syedahmed
October 19th, 2005, 02:44 PM
I Have to download a file(wsusscan.cab) from

http://go.microsoft.com/fwlink/?LinkId=40751.

I want the program to save the file in a specified directory on local computer.
I have been trying this for a week now and still no success.I know how to do it with FTP but HTTP is giving lot of problems.
Any help will be highly appreciated.

Thanks,
Ahmed.

PeejAvery
October 19th, 2005, 03:20 PM
What commands have you used for downloading the file. If they are part of the file system commands than it will not work unless you have read/write access to that server folder. My guess is that you do not.

syedahmed
October 20th, 2005, 08:30 AM
Thats a link open to evryone. One doesnot need password .Its open to the world on http.

PeejAvery
October 20th, 2005, 08:36 AM
Thats a link open to evryone. One doesnot need password .Its open to the world on http.
I understand that. But in a scripting language such as PERL or PHP, depending on how you plan to download it, you may have to open the directory for reading files. This would require read/write access. This is not the same as viewing a webpage. I am sure there are alternatives though.

mmetzger
October 20th, 2005, 11:49 AM
#!/usr/bin/perl

use LWP::Simple;
getstore('http://go.microsoft.com/fwlink/?LinkId=40751', 'c:\\myfile.cab');


Change the directory / filename based on what you need.

or as a one-liner:



perl -MLWP::Simple -e "getstore('http://go.microsoft.com/fwlink/?LinkId=40751', 'c:\\myfile2.cab');"

syedahmed
October 20th, 2005, 01:36 PM
Supose i want to download this pdf file from this site to my local directory.This script does do something as it takes time to complete it.When when i look for the file it not present on the computer.Pls help me on this as this is the bottleneck of my small project.

Thanks.


use XML::XPath;
use XML::XPath::XMLParser;
use LWP;
use File::Spec::Functions;

use Win32::OLE qw(in with);
use Win32::Internet;
use Win32;

use File::Spec::Functions;
my $parser = XML::XPath::Parser->new();
#my $dir = $ENV{'TEMP'}; # save downloads to...?



Win32::SetCwd("c:/Documents and Settings/abcd/Desktop/PERL-Project")
or die "couldnt setup the cwd" ;
my $browser = LWP::UserAgent->new(agent=>'Mozilla/4.76 [en] (Win98; U)');
my $url= 'http://www.copyright.gov/legislation/dmca.pdf';
my $response = $browser->get($url);

syedahmed
October 20th, 2005, 02:20 PM
perl -MLWP::Simple -e "getstore('http://go.microsoft.com/fwlink/?LinkId=40751', 'c:\\myfile2.cab');"


this worked thank you.

mmetzger
October 20th, 2005, 03:16 PM
Supose i want to download this pdf file from this site to my local directory.This script does do something as it takes time to complete it.When when i look for the file it not present on the computer.Pls help me on this as this is the bottleneck of my small project.

Thanks.


use XML::XPath;
use XML::XPath::XMLParser;
use LWP;
use File::Spec::Functions;

use Win32::OLE qw(in with);
use Win32::Internet;
use Win32;

use File::Spec::Functions;
my $parser = XML::XPath::Parser->new();
#my $dir = $ENV{'TEMP'}; # save downloads to...?



Win32::SetCwd("c:/Documents and Settings/abcd/Desktop/PERL-Project")
or die "couldnt setup the cwd" ;
my $browser = LWP::UserAgent->new(agent=>'Mozilla/4.76 [en] (Win98; U)');
my $url= 'http://www.copyright.gov/legislation/dmca.pdf';
my $response = $browser->get($url);

The problem is you don't actually do anything with the response object. You have to actually write the content to a file first. Or just adapt the LWP::Simple getstore() to use this if you don't need that specific user agent or need to perform any operations on the data before writing it to file. Take a look at LWP::Simple's documentation, it does most of what you need for simple downloading. The LWP::UserAgent / HTTP Request objects are useful for spoofing the referrer which a lot of sites use for verifying download links.