On Mon, Aug 23, 2010 at 09:06:18AM +0800, HU Chengzhe wrote:
> Hello,
>     when I  plan to implement some ftp client functions based on libcurl, I
> encounter some problems:
[...]
>     struct curl_slist *headerlist = NULL;
>     const char s[] = "PWD";
>     const char s1[] = "LIST ";

You can't do a LIST command as a pre- or post-quote command. A LIST requires
much more than just sending a command and awaiting the response; it involves
setting up a secondary data connection and performing a file transfer.
To perform a directory listing, put a slash at the of the URL (i.e. 
ftp://137.212.232.82//home/oamops/cid/) or use the CURLOPT_DIRLISTONLY
option.

>     const char s2[] = "CWD /home/oamops/cid";

Sending a CWD as a pre- or post-quote command is not recommended as it messes
up the ftp state machine.

>     headerlist = curl_slist_append(headerlist, s);   
>     headerlist = curl_slist_append(headerlist, s2);   
>    headerlist = curl_slist_append(headerlist, s1);   
>    curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
>  
>   /* As I am not sure the return list would be by header or data, 
>    * I try the two ways at same time

A directory listing is considered a data transfer, so it goes to the
WRITEFUNCTION.

>   */
>    curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, WriteMemoryCallback);
>    curl_easy_setopt(curl, CURLOPT_WRITEHEADER, (void *)&chunk);
>   
>   curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
>   curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);

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

Reply via email to