ok , so you are listing files from inside an FTP session? PHP has almost any kind of libraries you need to make life easy for you. check out the FTP module. you can use ftp_nlist() function to list files from remote server, then get the results and manipulate them as you wish.
Correct, but it doesn't provide you with any other information that is useful such as permissions, ownership, modified time, etc. That is why I am doing it this way.
This script isn't something I intend to release. It is being used on remote servers I have. The script has to be via FTP, as apache on that server doesn't run with enough permissions to the files/folders to to chmod.