cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: About getting file attibutes on FTP server using libcurl

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Wed, 25 Aug 2010 22:03:23 -0700

On Thu, Aug 26, 2010 at 10:37:00AM +0800, CHEN Xiaolei A wrote:
> Hello,
>
> I am using libcurl to implement FTP manipulations, and I got a problem when
> trying retrieving file attributes on FTP server.
>
> My solutions for retrieving file attributes listed below:
> (1) List dir and dump the result to memory
> curl_easy_setopt(curl, CURLOPT_URL, "ftp://135.252.13.96/");
> curl_easy_setopt(curl, CURLOPT_WRITEDATA, MyMemoStruct);
> ...
> curl_easy_perform(curl);
>
> So the result (something like executing "ls -l") will be stored in
> memory
>
> (2) Parse the memory string and get file attributes like "owner",
> "permission", "size", etc.

This parsing isn't done by libcurl, but by your app. There are libraries
available to help in doing so, since ftp LIST output isn't standardized.

> My question is:
> (1) If filename contains some special character in UTF-8 format, can the
> mothod above work well? If the filename become a clobber, and I use this
> clobber to download this file, can libcurl work well?

I don't believe the character set used by LIST is standardized; IIRC, there
have been ftp RFCs that deal with internationalization and deal with
this issue (e.g. MLSD command). libcurl will also use NLST when given
CURLOPT_DIRLISTONLY which is easier to parse and is a mandatory command.

> (2) Is there any other way to retrieve file attributes?

For some attributes (e.g. size, date), yes (libcurl gets those with the
CURLOPT_NOBODY option), but these are very slow since they involve a round-
trip for each file. Some servers probably support nonstandard extensions
to get more attributes, and the MLST command (in RFC 3659) provides more,
but only on those servers that support it.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-08-26