[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Perl Script to Download Files

Posted on 2010-11-18
4
Medium Priority
?
805 Views
Last Modified: 2012-06-21
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?

0
Comment
Question by:kyle972
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:jeromee
ID: 34169264
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

0
 

Author Comment

by:kyle972
ID: 34169575
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?
0
 
LVL 10

Accepted Solution

by:
jeromee earned 2000 total points
ID: 34169714
Since it's binary file, you will need to save it as such.
See the new version of the code.
BTW, I saved it w/ my browser and compare it with the file I downloaded using Perl and both are identical.

Good luck!
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.pgrbf00.grib2');
if( $res->is_success ) {
   open(BINFILE, ">/tmp/binfile") || die;
   binmode BINFILE;
   print BINFILE $res->content;
   close BINFILE;
}

Open in new window

0
 

Author Closing Comment

by:kyle972
ID: 34175168
Works perfect.  Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question