We help IT Professionals succeed at work.

Pulling only certain files with FTP using Perl

IDCSSupport
IDCSSupport asked
on
I need to pull certain files using perl from a client's FTP Server.
The file names being with EDI322_

What command can I use to only pull files that start with that?
Comment
Watch Question

BRONZE EXPERT
Commented:
The simplest isn't really using Perl - for more details see perldoc -f system and man ncftpget:

system('ncftpget', 'EDI322_*') or die $!

Open in new window


In perl, this should do it - for more details/options see perldoc Net::FTP:

use Net::FTP;
my $ftp = $Net::FTP->new('host') or die "could not connect: $@";
$ftp->login('username', 'password') or die "could not login: ", $ftp->message;
my @files = grep /^EDI322_/, $ftp->ls;
foreach my $fil (@files) { $ftp->get($fil) or die "get failed: ", $ftp->message; }

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.