cURL / Mailing Lists / curl-library / Single Mail

curl-library

About some FTP client functions by using libcurl

From: HU Chengzhe <Chengzhe.Hu_at_alcatel-sbell.com.cn>
Date: Thu, 19 Aug 2010 14:50:52 +0800

Hello,

      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
problems.
   
   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_global_init(CURL_GLOBAL_DEFAULT);

       curl = curl_easy_init();
       if(curl) {
           curl_easy_setopt(curl, CURLOPT_URL,
                     "ftp://135.252.234.82");
             //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 */
              curl_easy_cleanup(curl);
              if(CURLE_OK != res) {
                   fprintf(stderr, "curl told us %d\n", res);
               }
         }
  curl_global_cleanup();
}

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
getRootPath().

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
this:
-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,
Arkie
-----------------------------------------------------------------------
Alcatel Lucent Shanghai Bell
Mail: Chengzhe.Hu_at_alcatel-sbell.com.cn
-----------------------------------------------------------------------

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