The LS command is not giving what I expect in Net::FTP. I expected it to return an array of strings (filenames), but I get an array, containing an array of strings.
use strict;
use Net::FTP::Common;
my ($host, $user, $pw) = ('<ftp site>', 'user', 'pw');
my $ftp = new Net::FTP($host) || die;
$ftp->login($user, $pw) || die;
my $pwd = $ftp->pwd();
my $subDir = 'subdir/';
my $pattern = '*.txt';
$ftp->cwd($subDir);
$ftp->pasv(); # passive mode
my @files = $ftp->ls($pattern) || die;
$ftp->cwd($pwd);
The files array looks like this, for example:
@files[@array[0]] = ‘filename.txt’;
I’ve also tried not Changing Directories, and just doing $ftp->ls('subdir/*.txt'); with the same results.
Why is it doing this? I am misunderstanding the return value? This is on WINDOWS.
First, you should be using
instead of
since you use Net::FTP and not Net::FTP::Common.
Now on to your problem.
The documentation says:
which surely means
You’re calling it in scalar context. You want
You could call
lsin list context, then then you’d sacrifice error checking.