Link to home
Start Free TrialLog in
Avatar of kyle972
kyle972

asked on

Perl Script to Download Files

I need a perl script to download this file and save it to a directory on my computer.


ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.2010111800/gfs.t00z.pgrbf00.grib2

the file also exists as an http:

http://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs.2010111800/gfs.t00z.pgrbf00.grib2

I am behind a corporate proxy that uses an automatic configuration script which complicates the file download somewhat.

Any solutions?

Avatar of jeromee
jeromee
Flag of United States of America image

There might be a better way but this worked for me.
Please change the proxy settings of course
And I used a smaller file to test the download:

use strict;
use LWP::UserAgent;

my $browser = LWP::UserAgent->new( );
$browser->proxy('http', 'http://172.17.1.18:8080');	# proxy settings here!
my $res = $browser->get('http://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs.2010111800/gfs.t00z.pgrb2f78.idx');
print $res->content if $res->is_success;

Open in new window

Avatar of kyle972
kyle972

ASKER

Thanks for the reply.

However, the file becomes unusable to me when reading in and then outputting it. I need to save the file like you would if you were downloading it from a browser.  I can't lose the special formatting in this file.

I just need to save it. No reading or writing to another file.

Any other ideas?
ASKER CERTIFIED SOLUTION
Avatar of jeromee
jeromee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kyle972

ASKER

Works perfect.  Thanks