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');
my @filenames=$ftp->nlst('*');
print @filenames;

When I print it out, I get the following output:

If you guys have any input that would be great.


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');
my @filenames=$ftp->ls();
foreach (@filenames){
  print "$_\n";

This results in the output:

$ perl test.pl 

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

commented: Good test. +2
commented: Went above and beyond. +4

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

Awesome, thanks! Glad I could be of service :)