There are a huge number of FTP servers.
We have clients that use some obscure proprietary Windows-based servers and the list of files they return is completely different from the Linux versions.
So, what did I do for each file / directory entry, I'm trying to change the directory to it, and if that doesn't work, consider it a file :)
The following bullet proof method:
# Checks if the give file_name is actually a file. def is_ftp_file?(ftp, file_name) ftp.chdir(file_name) ftp.chdir('..') false rescue true end file_names = ftp.nlst.select {|fname| is_ftp_file?(ftp, fname)}
It works like a charm, but note: if there are many files in the FTP directory, this method takes some time to go through all of them. p>
source share