FTP-list of files
Ben Rubinstein
benr at cogapp.com
Fri Jul 5 09:49:01 EDT 2002
on 5/7/02 1:10 pm, Jan Schenkel at janschenkel at yahoo.com wrote:
>> But you'll have to parse the reply to extract only
>> the file names.
>>
>
> Which you can do easily by filtering the results, as
> files start with a '-' and folders/directories/however
> you like to call themstart with a 'd'.
Beware: this will work on many FTP servers, but by no means all. IIS offers
two formats - there's a checkbox on the control panel of the server to
determine which one FTP clients will see.
Tragically there is NO standard, only a number of conventions. Ludicrously,
the FTP RFC (standard) defines that an FTP server should respond to the LIST
command (which is what is being used here) with a listing in a 'human
readable' format, and doesn't specify it. There is another command (I think
NLIST, but my memory may be faulty) - which you'll have to hack libURL to
send - which is defined to be easy for machines to read - but this doesn't
include such useful information as whether this file is a directory or not.
AFAIK there is no simple correct solution; you just have to code a parser to
respond to all the formats you encounter/care about, and do lots of checking
to be that the format you think you are parsing is exactly right.
When I last looked into this, I hoped at least to find a helpful web page
somewhere that would say 'these X FTP servers account for approx Y% of the
installed base and these are the format(s) that each might respond to LIST
with'. But I found no such thing. I found quite a few code snippets in
various different languages/environments that claimed to parse FTP listings,
but actually only parsed one format; some that took account of a few. It's
a nightmare.
Of course, you may only be interested in a single case, in which case ignore
all of this and just look at what you're getting back from that server. If
you are trying to write a generally accurate parser - please share any
research you come up with!
Ben Rubinstein | Email: benr_mc at cogapp.com
Cognitive Applications Ltd | Phone: +44 (0)1273-821600
http://www.cogapp.com | Fax : +44 (0)1273-728866
More information about the use-livecode
mailing list