cURL / Mailing Lists / curl-library / Single Mail

curl-library

Problem of implementing ftp client--getRootPath()

From: HU Chengzhe <Chengzhe.Hu_at_alcatel-sbell.com.cn>
Date: Thu, 26 Aug 2010 22:54:19 +0800

Hello,
    I want to implement a ftp client based by libcurl and I encounter a
problem.
   (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
*data)
{
    return (size_t)(size * nmemb);
}

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

  curl_global_init(CURL_GLOBAL_DEFAULT);

  curl = curl_easy_init();
  if(curl) {
   
    curl_easy_setopt(curl, CURLOPT_URL,
                     "ftp://199.52.234.12");
    //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);
    }else{
       char str[100];
       res = curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, str);
       cout<<res<<" : "<<str<<endl;
 
    }
    curl_easy_cleanup(curl);
}
  
  curl_global_cleanup();
}
______________________________________________________
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,
Arkie

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-08-26