Zilore Mumba
Zilore Mumba

Reputation: 1500

how do I list contents of local directory on ftp?

I am trying to send files to a remote host via a Perl script. To do this I want list the local directory then choose files to upload as I iterate through the files list using the following commands:

my @files = '!ls'; does not work
my @files = 'lls'; does not work either

Then I want to do:

foreach my $file (@files) {
next if -d $file;
next unless $file =~ /^gateway_data/;
$ftp->put($file) or warn "Failed '$file': $! ($^E)";
}

Is there another command, apart from the two above, to make the list of files in the local directory? Assistance will be appreciated.

Upvotes: 0

Views: 2366

Answers (1)

ProfGhost
ProfGhost

Reputation: 359

opendir(my $DIR, './') or die $!;
my @files = readdir($DIR);
foreach my $file (@files) {
    next if -d $file;
    next unless $file =~ /^gateway_data/;
    $ftp->put($file) or warn "Failed '$file': $! ($^E)";
}

This should work.

Upvotes: 1

Related Questions