I haven't used FTP in years because of its security limitations (any protocol that sends passwords in plain text is best limited to use only on local networks), but if memory serves you can get a list of files from an FTP server in one line in LC:
Code: Select all
get url "ftp://user:pass@domain.com/path/to/files/"
if the result is not empty then -- handle connection error:
answer "Whoops!" && the result
else
-- do whatever you like with the list of files
end if
The trick there is that the URL path ends with "/", letting libURL know that you're asking for a list of directory contents rather than the contents of a specific file.
Most FTP commands in LiveCode will automatically handle directory changing, and when writing a file via FTP it'll also automatically handle the creation of any new directories needed to satisfy the specified path.
Python's a great language, but for many tasks I think you'll find some of the conveniences in LiveCode quite nice.
Tip: The FTP spec is notorious for allowing a wide range of inconsistencies with how file listings are delivered. For example, date/time stamps may sometimes only include the month and date (if within the previous 12 months), while otherwise using a wide range of allowable date formats. There are other allowances as well, perhaps easy to account for if you're dealing with only one server, but potentially troublesome if you need to write a tool that can work with any FTP server.
If this is a server you control, you can get more consistent file listings using a CGI called via HTTP/HTTPS instead. This will usually also be much faster, and if the filenames are sensitive can also provide security by using HTTPS so everything is encrypted over the wire.
If using LiveCode Server as the CGI, you get get a list of files with creation dates, mod dates, and other useful details with:
Code: Select all
set the directory to tSomeSpecifiedPath
put the detailed files into tFileList