1

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.

  • http://stackoverflow.com/questions/1244095/c-ftp-library http://stackoverflow.com/questions/259166/good-free-ftp-client-library-for-windows-c-commercial-apps http://cr.yp.to/ftpparse.html ... That's from 30 seconds on Google. Did you look into any of those? – derobert Oct 24 '11 at 20:05
  • @derobert I tried Googling but I couldn't find those. I'll take a look at ftpparse. –  Oct 24 '11 at 20:10
  • 1
    I googled for: `ftp LIST library` to find ftpparse. – derobert Oct 24 '11 at 20:14

2 Answers2

1

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
0

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.

Vladius
  • 4,268
  • 2
  • 20
  • 21