cURL / Mailing Lists / curl-library / Single Mail

curl-library

FTP Upload Crash!! (Win32 libcurl DLL) Help me.

From: ¸Í¿µ±¹ <mytechbox_at_gmail.com>
Date: Fri, 11 Jan 2008 12:57:29 +0900

Hi all,

I¡¯m developing FTP upload program with libcurl win32 DLL using MSVC++6.

But, the program has occurs memory error after FreadCallback() was
performed.

I read the libcurl manual and saw the ftpupload example, But I cannot solve
the problem. K

 

I saw the notes in ftpupload.c example file

/* NOTE: if you want this example to work on Windows with libcurl as a

  DLL, you MUST also provide a read callback with

  CURLOPT_READFUNCTION. Failing to do so will give you a crash since a

  DLL may not use the variable's memory when passed in to it from an app

like this. */

but I don¡¯t know how to apply that on my program.

Please, help me. T_____T

 

------------------------------------------------------------------------ my
source code

#define LOCAL_FILE "c://futest.txt"

#define UPLOAD_FILE_AS "futest.txt"

#define REMOTE_URL "ftp://futest:futest1234@211.201.128.155/"
UPLOAD_FILE_AS

#define RENAME_FILE_TO "futest.txt"

 

int FUProc::Begin()

{

    CURL *curl;

    CURLcode res;

    FILE * hd_src ;

    int hd ;

    struct stat file_info;

    

    struct curl_slist *headerlist=NULL;

    static const char buf_1 [] = "RNFR " UPLOAD_FILE_AS;

    static const char buf_2 [] = "RNTO " RENAME_FILE_TO;

 

    /* get the file size of the local file */

    if((hd = open(LOCAL_FILE, O_RDONLY)) == -1)

    {

        return -1;

    }

    fstat(hd, &file_info);

    close(hd);

    

    if(!(hd_src = fopen(LOCAL_FILE, "rb")))

    {

        return -2;

    }

 

    curl_global_init(CURL_GLOBAL_ALL);

    curl = curl_easy_init();

 

    if(curl)

    {

        /* build a list of commands to pass to libcurl */

        headerlist = curl_slist_append(headerlist, buf_1);

        headerlist = curl_slist_append(headerlist, buf_2);

        

        /* enable uploading */

        curl_easy_setopt(curl, CURLOPT_UPLOAD, 1) ;

        

        /* specify target */

        curl_easy_setopt(curl,CURLOPT_URL, REMOTE_URL);

        curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);

        curl_easy_setopt(curl, CURLOPT_READFUNCTION, FreadCallback);

        curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);

        curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_info.st_size);

        curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);

        curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, ProgressCallback);

        

        res = curl_easy_perform(curl);

        

        curl_slist_free_all (headerlist );

        curl_easy_cleanup(curl);

    }

    fclose(hd_src); /* close the local file */

    

    curl_global_cleanup();

    return 0;

}

 

size_t FUProc::FreadCallback(void *ptr, size_t size, size_t nmemb, void
*stream)

{

    return fread(ptr, size, nmemb, (FILE *)stream);

}

 

int FUProc::ProgressCallback(void *clientp, double dn_total, double dn_now,
double up_total, double up_now)

{

    m_total = up_total;

    m_now = up_now;

    return 0;

}

 
Received on 2008-01-11