Getting a Directory Listing From an FTP Server
Good morning, Mr. Lord ... :)
For ftp urls, just use
get url and provide a url that ends in "/".
What you get with an http url will depend on the server configuration. Usually the index.html page if it exists, and possibly an html-formatted directory listing it doesn't. But not all http servers return directory listings.put "ftp://ftp.somewhere.com/elsewhere/" into tUrl get url tUrl
Posted 8/2/2002 by Dave Cragg to the MetaCard ListAddendum 2/23/06 by Ken Ray: Don't forget that you would need to provide the user name and password for most FTP servers, so here's a generic example as a one-liner:
What you get back is a true directory listing, that is delimited by spaces, as in:put url "ftp://username:firstname.lastname@example.org/elsewhere/" into tListing
Note also that the date column does not include the year (at least not on my Linux server). To parse this, here's some code that can help extract the data into a tab-delimited format for display in a table field and converts the date to appropriate "short date and time" format:
drwxr-x--x 6 iedev sonsothundergrp 4096 Feb 7 03:37 .
drwxr-xr-x 923 root root 24576 Feb 23 10:06 ..
-rw-r--r-- 1 iedev sonsothundergrp 24 Oct 7 19:02 .bash_logout
-rw-r--r-- 1 iedev sonsothundergrp 191 Oct 7 19:02 .bash_profile
-rw-r--r-- 1 iedev sonsothundergrp 124 Oct 7 19:02 .bashrc
drwxrwxr-x 3 iedev sonsothundergrp 4096 Feb 22 05:54 My Folder
drwxrwxr-x 5 iedev sonsothundergrp 4096 Oct 15 05:27 My Other Folder
drwxrwxrwx 3 iedev sonsothundergrp 4096 Feb 22 17:04 Her Folder
drwxrwxr-x 3 iedev sonsothundergrp 4096 Feb 8 04:55 Another Folder
lrwxrwxrwx 1 iedev sonsothundergrp 17 Oct 7 19:02 www -> /www/sonsothunder
on mouseUp put url "ftp://username:email@example.com/elsewhere/" into tListing put stsFormatFTPListing(tListing) into fld 2 end mouseUp function stsFormatFTPListing pData put "" into tNewData repeat for each line tLine in pData put replaceText(word 1 to 5 of tLine," +",tab) & tab after tNewData put replaceText(word 6 to 8 of tLine," +"," ") into tDateTime put _stsFixDateTime(tDateTime) & tab after tNewData put word 9 to (the number of words of tLine) of tLine & cr after tNewData end repeat delete char -1 of tNewData return tNewData end stsFormatFTPListing function _stsFixDateTime pDateTime -- Checks the date on the server to see if it is later than the current date; -- if so, it subtracts a year, otherwise we leave it alone put word -1 of the long date into tYear put word 1 to 2 of pDateTime into tDate put word -1 of pDateTime into tTime put tDate & ", " & tYear && tTime into tTest convert tTest to seconds if the seconds < tTest then -- "future", so subtract 1 put tYear - 1 into tYear end if put tDate & ", " & tYear && tTime into tDateTime convert tDateTime to short date and time return tDateTime end _stsFixDateTime