Listing all files on a ftp server

Éric Chatonet eric.chatonet at
Sat Feb 5 18:27:34 EST 2005


I saw a few days ago questions and right answers about a script that 
would look at 1 directory and provide a complete hierarchial list of 
all files within all folders and subfolders.
Here is a complementary function for tracking all files within all 
folders and subfolders on a FTP server.
I did not test it yet on windows nor Linux but it works fine with OS X.

put word 1 to -1 of AllFilesOnServer("/www/") -- any folder on the 
server finishing by a slash
function AllFilesOnServer pStartDir
   local tUserName,tPassword,tServer,tPort,tUrl,tDirectories,tDir, 
tFoldersList, tFilesList, tOtherFilesList
   put fld "FTPUserName" into tUserName -- from user prefs
   put fld "FTPPassword" into tPassword -- from user prefs
   put fld "FTPServerAddress" into tServer -- from user prefs
   put fld "FTPPort" into tPort -- from user prefs
   if tPort = empty then put 21 into tPort
   replace numToChar(13) with empty in pStartDir -- important
   put "ftp://" & tUserName & colon & tPassword & "@" & tServer & colon 
& tPort & pStartDir into tUrl
   if the platform = "MacOS" then put isotoMac(URL tUrl) into 
   else put URL tUrl into tDirectories
   if the result = empty then
     sort tDirectories
     replace numToChar(13) with empty in tDirectories
     repeat for each line tDir in tDirectories
       set cursor to busy
       if "." is not in tDir then put pStartDir & FormatAsFolder(tDir) & 
cr after tFoldersList -- Æ
       else put pStartDir & tDir & cr after tFilesList
       -- assuming that all files have an extension (.php, .gif, etc.)
       -- if not sure, use a try structure instead
     end repeat
     if tFoldersList <> empty then
       delete last char of tFoldersList
       repeat for each line tFolder in tFoldersList
         put AllFilesOnServer(tFolder) into tList -- recursion
         if tList <> empty then put tList after tOtherFilesList
       end repeat
     end if
     return tFilesList & tOtherFilesList
   else return the result -- error
end AllFilesOnServer
function FormatAsFolder pPath
   if last char of pPath <> slash then return pPath & slash
   return pPath
end FormatAsFolder


Eric Chatonet.
So Smart Software
For institutions, companies and associations
Built-to-order applications: management, multimedia, internet, etc.
Windows, Mac OS and Linux... With the French touch
Web site
Email		eric.chatonet at
Phone		33 (0)1 43 31 77 62
Mobile		33 (0)6 20 74 50 86

More information about the Use-livecode mailing list