FTP download using perl script

Need assistance

I have a script which i can download the files from ftp server using perl . But i want to download multiple files at a time

#!/usr/bin/perl -w

use Net::FTP;
$ftp = Net::FTP->new("ftp.ncdc.noaa.gov");
$ftp->login('username', 'password');
$ftp->cwd("<dir>");
$ftp->binary;
$ftp->get("471560-99999-2013.op.gz");
$ftp->quit();

I have 20 or more files on the ftp server which i want to automate this script to get all the files at a time

140310-99999-2012.op.gz 
276120-99999-2012.op.gz 
284400-99999-2012.op.gz
339900-99999-2012.op.gz
345600-99999-2012.op.gz
347200-99999-2012.op.gz
031530-99999-2012.op.gz
031600-99999-2012.op.gz
032140-99999-2012.op.gz
032220-99999-2012.op.gz
033820-99999-2012.op.gz
036930-99999-2012.op.gz
064500-99999-2012.op.gz
071300-99999-2012.op.gz
072000-99999-2012.op.gz
100220-99999-2012.op.gz
104240-99999-2012.op.gz
107275-99999-2012.op.gz
723658-23090-2012.op.gz

Untested:

#!/usr/bin/perl -w

use Net::FTP;
$ftp = Net::FTP->new("ftp.ncdc.noaa.gov");
$ftp->login('username', 'password');
$ftp->cwd("<dir>");
$ftp->binary;

my @files = qw /
                140310-99999-2012.op.gz
                276120-99999-2012.op.gz
                284400-99999-2012.op.gz
                339900-99999-2012.op.gz
                345600-99999-2012.op.gz
                347200-99999-2012.op.gz
                031530-99999-2012.op.gz
                031600-99999-2012.op.gz
                032140-99999-2012.op.gz
                032220-99999-2012.op.gz
                033820-99999-2012.op.gz
                036930-99999-2012.op.gz
                064500-99999-2012.op.gz
                071300-99999-2012.op.gz
                072000-99999-2012.op.gz
                100220-99999-2012.op.gz
                104240-99999-2012.op.gz
                107275-99999-2012.op.gz
                723658-23090-2012.op.gz
            /;

foreach (@files) {
    print "get-ing file: $_\n";
    $ftp->get($_);
}

$ftp->quit();

Thank you balajesuri.

Is there a way that we can create a file and add .gz files to it and use that file and create a loop to download all the .gz files

change the static file list declaration in balajesuri's script abpve to my @files=$ftp->ls()

On the FTP site there are 10000 files which i dont want to download all of them . I only want some 20 files . If i specify

my @files=$ftp->ls()

it will download all the files. Any other idea are appreciated

Then simply fill the array from your file

open (my $to_collect , '<', 'files_to_collect');
my@file=(<$to_collect>)
...

This work great . Thank you everyone for assisting me .

download works great.

Last thing : I would like to download to a specific path on the local server . Any ideas!!!!

Please take a look at perldoc for Net::FTP

Thank you for giving me the information .Can you give me an example

Well, at this point, you have all the necessary tools. My suggestion is: cook up a test perl program and play around with the "get" routine of Net::FTP and see how it works.

Please give it a try and let us know where you're stuck.