cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Capture the result of FTP command

From: Sundar, Karthik <Karthik.Sundar_at_nielsen.com>
Date: Fri, 7 Nov 2008 10:08:19 +1100

Hi Dan,

 

I tried ..but couldn't get the size..It returns file size as 0.

 

Can you please tell me watz wrong in the code below?

 

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <curl/curl.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <errno.h>

#include <unistd.h>

#define REMOTE_URL "ftp://enterprise\\user:pwd@10.228.13.21/
<ftp://enterprise/user:pwd@10.228.13.21/> "

#define DEST_FILE_IN "/FTPTest"

 

int main(int argc, char **argv)

{

       CURL *curl;

     CURLcode res;

     CURLcode res2;

     int i;

     int hd ;

     char ss;

     int code;

     struct stat file_info;

     struct curl_slist *headerlist=NULL;

     char buf_1[10000];

       int numRead;

       int response;

       int filesize;

       int size;

 

 

       memset(buf_1, 0, sizeof(buf_1));

       curl_global_init(CURL_GLOBAL_ALL);

       curl = curl_easy_init();

       

 

       if(curl) {

       

            // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);

            

             /* CWD to change the directory */

             curl_easy_setopt(curl,CURLOPT_URL, REMOTE_URL);

         sprintf(buf_1, "CWD %s" ,DEST_FILE_IN );

         headerlist = curl_slist_append(headerlist, buf_1);

             curl_easy_setopt(curl, CURLOPT_QUOTE, headerlist);

         res = curl_easy_perform(curl);

 

         /* Reinitialize the list */

             headerlist =NULL;

             memset(buf_1, 0, sizeof(buf_1));

 

             /*Size of the specific file */

             sprintf(buf_1, "SIZE ftplog");

             

            //

curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&response);

             headerlist = curl_slist_append(headerlist, buf_1);

             curl_easy_setopt(curl, CURLOPT_QUOTE, headerlist);

         curl_easy_setopt(curl,CURLOPT_NOBODY,1);

             res2 = curl_easy_perform(curl);

 

             size =

curl_easy_getinfo(curl,CURLINFO_CONTENT_LENGTH_DOWNLOAD,&filesize);

             printf("FILE SIZE:%d\n",filesize);

            // printf("CODE:%d\n",response);

 

 

             if( CURLE_OK == res2 )

             {

                   printf("FILE EXIST:\n");

 

             }

             else

             {

           // printf("ERROR NO :%d\n",res2);

           // printf("ERROR MSG :%s\n",curl_easy_strerror( res2 ));

                  printf("File doesn not exist\n");

 

         }

             curl_slist_free_all (headerlist);

         curl_easy_cleanup(curl);

             

  }

 

 curl_global_cleanup();

 return 0;

 

}

 

 

 

Thanks in advance

Karthik S

 

Date: Wed, 5 Nov 2008 22:43:47 -0800

From: Dan Fandrich <dan_at_coneharvesters.com>

Subject: Re: Capture the result of FTP command

To: curl-library_at_cool.haxx.se

Message-ID: <20081106064346.GA17721_at_coneharvesters.com>

Content-Type: text/plain; charset=us-ascii

 

On Thu, Nov 06, 2008 at 05:17:33PM +1100, Sundar, Karthik wrote:

> I am getting the output printed as

>

> > SIZE bd

>

> < 213 1501184

>

>

> Please let me know how to get the size ?1501184? in a variable.

 

You could install a header callback function which ought to give you
that data. But since libcurl already calls SIZE, just do a
CURLOPT_NOBODY request and extract the size using the curl_easy_getinfo
CURLINFO_CONTENT_LENGTH_DOWNLOAD parameter.

 

>>> Dan

-- 
http://www.MoveAnnouncer.com <http://www.moveannouncer.com/>
The web change of address
service
          Let webmasters know that your web site has moved
Received on 2008-11-07