cURL / Mailing Lists / curl-library / Single Mail


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

From: Ϳ <>
Date: Fri, 11 Jan 2008 12:57:29 +0900

Hi all,

Im developing FTP upload program with libcurl win32 DLL using MSVC++6.

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

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 dont 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@"

#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);



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


        return -2;




    curl = curl_easy_init();




        /* 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_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);

        curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, ProgressCallback);


        res = curl_easy_perform(curl);


        curl_slist_free_all (headerlist );



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



    return 0;



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


    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