I am using libcURL to get a list of directories on an FTP server. The problem is that FTP's LIST
command's output is not well defined and it differs per server.
Is there a free library that parses common formats? It has to work on Mac OS X.
I am using libcURL to get a list of directories on an FTP server. The problem is that FTP's LIST
command's output is not well defined and it differs per server.
Is there a free library that parses common formats? It has to work on Mac OS X.
Many servers nowadays support the MLSD
and MLST
commands (see RFC 3659 Section 7), which have well-defined responses to address this very issue. You should use those before falling back to the old LIST
command.
There are a LOT of LIST
formats still being used online. Though not a solution for your particular project, Indy implements several dozen parsers in its library, so I know it is not a simple task to support LIST
very easily.
As mentioned you can used the MLSD FTP command to get the formatted listing output (RFC 3659 Section 7). To do this, add the following call to your curl_'s:
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST , "MLSD");
The output will then be something like that:
type=file;modify=20130319142533;size=8; EXAMPLE.txt
As you can see there are key=value;
pairs that can be parsed easily.