Dan,
    Thank you for your qucikly answer.

    But I am still confused about pre- or post-quote command usage.
    As  you said "Sending a CWD as a pre- or post-quote command is not 
recommended as it messes up the ftp state machine",
   so why do that would mess up the dtp state machine? Could you please explain 
more about this topic?
     Thank you very much.


Best Regards, 
Hu Chengzhe(胡成�矗�
----------------------------------------------------------------------- 
Alcatel Lucent Shanghai Bell
oambase-wtk Team 
Telephone: +86 10 8477 7579
Mail:  [email protected] 
----------------------------------------------------------------------- 

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Dan Fandrich
Sent: 2010年8月23日 11:26
To: [email protected]
Subject: Re: The problem of implementing ftp client function: listDirContents()

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
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to