> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Xu, 
> Qiang (FXSGSC)
> Sent: Wednesday, November 11, 2009 6:45 PM
> To: libcurl development
> Subject: RE: response to quoted pwd command in libcurl
> 
> To get the response to the command "pwd", what shall I do?

>From http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTWRITEHEADER 
>and http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTHEADERFUNCTION, 
>it is clear that to get the feedback to the quoted cmd like "pwd", at least 
>CURLOPT_WRITEHEADER must be pointed to a File pointer: 
========================================================================
/* from http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTWRITEHEADER 
*/
CURLOPT_WRITEHEADER 

(This option is also known as CURLOPT_HEADERDATA) Pass a pointer to be used to 
write the header part of the received data to. If you don't use your own 
callback to take care of the writing, this must be a valid FILE *. See also the 
CURLOPT_HEADERFUNCTION option above on how to set a custom get-all-headers 
callback. 

/* from 
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTHEADERFUNCTION */
CURLOPT_HEADERFUNCTION 

Function pointer that should match the following prototype: size_t function( 
void *ptr, size_t size, size_t nmemb, void *stream);. This function gets called 
by libcurl as soon as it has received header data. The header callback will be 
called once for each header and only complete header lines are passed on to the 
callback. Parsing headers should be easy enough using this. The size of the 
data pointed to by ptr is size multiplied with nmemb. Do not assume that the 
header line is zero terminated! The pointer named stream is the one you set 
with the CURLOPT_WRITEHEADER option. The callback function must return the 
number of bytes actually taken care of, or return -1 to signal error to the 
library (it will cause it to abort the transfer with a CURLE_WRITE_ERROR return 
code). 

If this option is not set, or if it is set to NULL, but CURLOPT_HEADERDATA 
(CURLOPT_WRITEHEADER) is set to anything but NULL, the function used to accept 
response data will be used instead. That is, it will be the function specified 
with CURLOPT_WRITEFUNCTION, or if it is not specified or NULL - the default, 
stream-writing function. 

It's important to note that the callback will be invoked for the headers of all 
responses received after initiating a request and not just the final response. 
This includes all responses which occur during authentication negotiation. If 
you need to operate on only the headers from the final response, you will need 
to collect headers in the callback yourself and use HTTP status lines, for 
example, to delimit response boundaries. 
========================================================================
So, it looks that I should fopen() a file to retrieve the command feedback.

The code is changed as follows: 
========================================================================
File *fHeader = NULL;
CURL *handle = NULL;
struct curl_slist *headers;
...
handle = curl_easy_init();
...
curl_easy_setopt(CURLOPT_URL, "sftp://13.198.98.190/";); 
...
headers = curl_slist_append(headers, "pwd");
curl_easy_setopt(handle, CURLOPT_QUOTE, headers); 
curl_easy_setopt(handle, CURLOPT_HEADER, 1); /* Is it necessary? I don't know. 
*/
curl_easy_setopt(handle, CURLOPT_WRITEHEADER, fHeader);
...
curl_easy_perform(handle);
...
curl_slist_free_all(headers);
curl_easy_cleanup(handle);
========================================================================
Is it OK now? Still, I am not sure how to do this in command-line to see the 
command feedback. Any idea?

Thanks,
Xu Qiang
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to