cURL / Mailing Lists / curl-library / Single Mail


Problem of implementing ftp client--getRootPath()

From: HU Chengzhe <>
Date: Thu, 26 Aug 2010 22:54:19 +0800

    I want to implement a ftp client based by libcurl and I encounter a
   (1)getRootPath(), it's a function and return a absolute path for ftp
server root directory. My code is as follow:
 static size_t throw_away(void *ptr, size_t size, size_t nmemb, void
    return (size_t)(size * nmemb);

int main(void){
     CURL *curl;
  CURLcode res;


  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL,
    //set username for transfer
    curl_easy_setopt(curl, CURLOPT_USERNAME, "user");

    //set password for transfer
    curl_easy_setopt(curl, CURLOPT_PASSWORD, "user");

    curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
   curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, throw_away);
    curl_easy_setopt(curl, CURLOPT_HEADER, 0L);

    res = curl_easy_perform(curl);

    if(CURLE_OK != res) {
      /* we failed */
      fprintf(stderr, "curl told us %d\n", res);
       char str[100];
       res = curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, str);
       cout<<res<<" : "<<str<<endl;
expected result: print "0 : root path"
actual result: print "0 :", there is no root path

(1)Is there anyone can tell me what's wrong with my code?
(2) Is it the best way to getRootPath based on libcurl?

Thank you in advanced.

Best Regards,

List admin:
Received on 2010-08-26