Doing the Perl curl

A while back I wrote a post about a ftp shell script. A number of people told me I should use curl instead. Here is one I wrote using both perl and curl to move some files from a site. I start with a list of file names. They don’t have the .pdf extension in the list, so I add that as part of the script. I iterate through the list and pull each file from an ftp server that using curl. Here’s the scoop:

#!/usr/bin/perl

my $movefile;
my @downloadlist;

open (MOVELIST, ‘/Volumes/FireWire/clients/acme/orders/orderlist.txt’);
my $downloadpath = ‘/Volumes/FireWire/clients/acme//pdfs/’;
my $connectPath = ‘ftp://myname:mypassword@192.133.1.234/sitedirectory/acme/sitepdfs/’;

while <> {
chomp $_;
push (@downloadlist, $_);
ftpFetch();
}

sub ftpFetch {
foreach $movefile(@downloadlist){
my $fileName = $movefile . “.pdf”;
system(qq|curl “$connectPath$fileName” -o “$downloadpath$fileName”|);
}
}

The -o flag tells curl where to put the file. You can use an -s flag if you don’t want the activity curl writes to the terminal. If you have installed curl, you can do a man curl to learn more.

Comments are closed.