FTP download using perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP download using perl script
# 1  
Old 06-06-2013
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

Code:
#!/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

Code:
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

# 2  
Old 06-06-2013
Untested:

Code:
#!/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();

# 3  
Old 06-07-2013
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
# 4  
Old 06-07-2013
change the static file list declaration in balajesuri's script abpve to my @files=$ftp->ls()
# 5  
Old 06-07-2013
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
Code:
my @files=$ftp->ls()

it will download all the files. Any other idea are appreciated
# 6  
Old 06-07-2013
Then simply fill the array from your file
Code:
open (my $to_collect , '<', 'files_to_collect');
my@file=(<$to_collect>)
...

# 7  
Old 06-07-2013
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!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Bash script for FTP download -Mysql

Hi guys, I recently managed to write up my working script, but now I have a problem. If the file isn't there in the remote server, my actual script jumps it and all ok, but I need something like this: Search file -> if there, then download -> if not, download next file in the list. Any... (7 Replies)
Discussion started by: virtus96
7 Replies

2. Shell Programming and Scripting

Download latest file via ftp server unix through shell script

Hello this is my first post in this forum , I dont want to be unhappy.. I am writing one script but facing difficulty to find the latest file with some new pattern My requirement is 1. The file is coming like "ABCD-23220140303" at FTP server once in a week. 2. script will run on daily... (3 Replies)
Discussion started by: ajju
3 Replies

3. Shell Programming and Scripting

Download files every one second using ftp script

Our main Server "Srv1" is used to generate text files based on specified criteria and it is also connected to two clients (pc1 and pc2) which are responsible for getting the files from Srv1 as it follows: 1. pc1 ( which represents my UNIX machine ) uses shell script to copy the files from Srv1 2.... (3 Replies)
Discussion started by: arm
3 Replies

4. Shell Programming and Scripting

Need of shell script to download data using ftp

Hi ! I am just wondering shell script to download data from ftp... I have text file containing ftp address...looks like this ftp://site...../filename.xyz ftp://site...../filename.xyz ftp://site...../filename.xyz ftp://site...../filename.xyz script has to read ftp address and... (8 Replies)
Discussion started by: nex_asp
8 Replies

5. Shell Programming and Scripting

ftp script doesn't download jpg properly

ftp script doesn't download jpg properly The downloaded files have color splotches Here is the script: ftp -n me@institute.edu <<END_SCRIPT quote user name quote pass password prompt mget *.jpg quit END_SCRIPT exit 0 cd ../ (2 Replies)
Discussion started by: walforum
2 Replies

6. Shell Programming and Scripting

Help on FTP download using UNIX script

Hi guys, I'm new on this forum and on UNIX. Can somebody help in writing a script to download a file from an FTP server and validating if there is a file to download. If there is a file, I would send it to a mail recipient and if not I would generate an error log. Thanks in advance!:D (1 Reply)
Discussion started by: rjay_45
1 Replies

7. Shell Programming and Scripting

Corrupted Download with Net::FTP (perl)

Hello, I am trying to download several files from a remote FTP server using Net::FTP from within a perl script. The files download alright, except they appear to be corrupted. I know this because once after downloading, I use bzcat to pipe the files to a split command, and bzcat complains saying... (3 Replies)
Discussion started by: amcrisan
3 Replies

8. Shell Programming and Scripting

Perl Script to resume download

Hi, i am looking for a perl script that can resume broken download images from a remote server. Can anyone help me on this. thanks, Vince (1 Reply)
Discussion started by: vin_eme
1 Replies

9. Shell Programming and Scripting

Same time ftp download in perl multiple sites.

I currently have a perl script that have to retreive a single file from 20+ sites every 10 min. Right now it will ftp to site1 and download and continue up until site20. I am trying to get this to run all the ftp d/l at the same time. This is where I have my problem, I can't get it to work. ... (5 Replies)
Discussion started by: kofs79
5 Replies

10. Shell Programming and Scripting

script for download files from ftp site

I'm new to scripting. I'm trying to write a script to download files from ftp site, the following is the script and the message i get after running the script. no files were downloaded :( Thanks advance! script: #!/usr/bin/ksh DAY=`date --date="-1 days" +%y%m%d` ftp -v -n "ftp.address" <<... (5 Replies)
Discussion started by: tiff-matt
5 Replies
Login or Register to Ask a Question