cURL / Mailing Lists / curl-library / Single Mail


About some FTP client functions by using libcurl

From: HU Chengzhe <>
Date: Thu, 19 Aug 2010 14:50:52 +0800


      I'm planing to implement a ftp client using libcurl. But when I
try to implement some basic functions of ftp client, I encounter some
   1) getRootPath(), this function should return ftp server root path by
absolute path format. my code as follow:
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, "hello");

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

              struct curl_slist *headerlist = NULL;
              const char s[] = "PWD";
               headerlist = curl_slist_append(headerlist, s);
              curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
              res = curl_easy_perform(curl);

               /* always cleanup */
              if(CURLE_OK != res) {
                   fprintf(stderr, "curl told us %d\n", res);

expected result: print ftp server root path
actual result: list all flie and directory information which are under
ftp server root path, just like this:
-r--r--r-- 1 oamops oamgroup 9539 Jul 9 2008 .alias_oam
-rw------- 1 oamops oamgroup 1612 Aug 4 18:50 .bash_history
-r--r--r-- 1 oamops oamgroup 7815 Feb 3 2010 .cshrc
-r--r--r-- 1 oamops oamgroup 3268 Nov 19 2009 .cshrc.oamops
-rw-r----- 1 oamops oamgroup 2309 Aug 18 14:33 .history
-rw-r--r-- 1 oamops oamgroup 157 Jul 19 15:43 .login
-rw------- 1 oamops oamgroup 30860 Jul 26 10:59 .lsof_zsups382
-rw-r--r-- 1 oamops oamgroup 253 Jul 19 17:26 .profile

so is there anyone can tell me why the result is like this? If this way
can't work, please tell me how to implement the function of

2)getNodeType(), this function should return a node type, it may be file
or directory. But until now, I have no idea about implementing it.
Is there any API can be called? or other convenient way? The worsest way
seems need a complicated string parse function to parse a string like
-rw-r--r-- 1 oamops oamgroup 253 Jul 19 17:26 .profile

3)getPermission(), this function should return the access permission of
a file or directory.
The difficulty is same as problem 2). Is there convenient way to
implement it?

Thank you for your answer kindly.

Best Regards,
Alcatel Lucent Shanghai Bell

List admin:
Received on 2010-08-19