[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Perl Script to Download Files

Posted on 2010-11-18
4
Medium Priority
?
789 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

872 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