Hey Daniweb,

I am looking to FTP into a server, take a list of filenames, and store them into an array, so I can eventually write them into a text file.

I am currently having an issue with the storing of the ls into a local array:

use Net::FTP;
$ftp = Net::FTP->new("slawas1");
$ftp->login('username', 'password');
$ftp->cwd("/directory/path");
my @filenames=$ftp->nlst('*');
$ftp->quit;
print @filenames;

When I print it out, I get the following output:
Net::FTP::A=GLOB(0x20513318)

If you guys have any input that would be great.

Thanks!

I should specify that the file that I ultimately want to write the list of text files to would be a local test file. I have looked through the NET::FTP library and haven't been able to find anything that might assist with this.

I basically want to mock the unix command "ls -1 blank.txt"

Hmm... I'm not familiar with the 'nlst' command. What happens if you use 'ls' instead? For me, 'ls' gives me a directory listing, neatly stored in @filenames.

If I remember correctly nlst returns just the filenames, while ls will return a multitude of information. For my purposes, all I need is the file name including extension.

You might want to give 'ls' a try! In my test (using your script) 'ls' returned just filenames.

use Net::FTP;
$ftp = Net::FTP->new("mysite.com");
$ftp->login('xxxx', 'xxxx');
$ftp->cwd("/private/test");
my @filenames=$ftp->ls();
$ftp->quit;
foreach (@filenames){
  print "$_\n";
}

This results in the output:

$ perl test.pl 
test5.txt
test4.txt
test2.txt
test1.txt
test3.txt

My ftp server doesn't even recognize an 'nlst' command.
I hope this helps!
-G

Comments
Good test.
Went above and beyond.

So weird... Totally worked.. Thanks for your help. Upvotes for you!

This question has already been answered. Start a new discussion instead.