cURL
Haxx ad
libcurl

Shopping cart software, Online file storage, Online photo storage, Hosted shopping cart, Contact management software, Email marketing software, Project management software, Issue tracking software, Online notepad, Web publishing software

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-library Archives

RE: response to quoted pwd command in libcurl

From: Xu, Qiang (FXSGSC) <Qiang.Xu_at_fujixerox.com>
Date: Wed, 11 Nov 2009 19:02:20 +0800

> -----Original Message-----
> From: curl-library-bounces_at_cool.haxx.se
> [mailto:curl-library-bounces_at_cool.haxx.se] 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
Received on 2009-11-11

These mail archives are generated by hypermail.

donate! Page updated November 16, 2009.
web site info

File upload with ASP.NET