curl-library
RE: About getting file attibutes on FTP server using libcurl
Date: Thu, 26 Aug 2010 13:41:40 +0800
Thanks Dan.
Our FTP server's OS is Sun Solaris, I tried option "CURLOPT_DIRLISTONLY", but it just printed the name of files. I need to get more attributes, especially for "permission" and "file type", so I think I have to parse that memory string anyway.
Regards,
Atlantis
-----Original Message-----
From: curl-library-bounces_at_cool.haxx.se [mailto:curl-library-bounces_at_cool.haxx.se] On Behalf Of Dan Fandrich
Sent: 2010Äê8ÔÂ26ÈÕ 13:03
To: curl-library_at_cool.haxx.se
Subject: Re: About getting file attibutes on FTP server using libcurl
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
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-08-26