cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: libcurl segfaults on file transfer

From: Ryan <rcdetert_at_ucdavis.edu>
Date: Mon, 16 Aug 2004 00:46:13 -0700

ah... I see what you mean. I need to be doing this for _every_ transfer.
I seem to have missed that and just thought I needed to do it once until
a cleanup() I was thinking I needed to do it just once. This code seems
to work.

thanks! libcurl is very nice.

void curlFilesToServer(void){
        DIR *d;
        struct dirent *pdirent;
        char relPath[100] = "";
        char newPath[103] = "./";
        int retVal;
        char firstTime = 1;
        
        //now curl it to a remote server
        struct curl_httppost* post = NULL;
        struct curl_httppost* last = NULL;
        CURL *hCURL;

        hCURL = curl_easy_init();
                
        d = opendir(logdir);
        while ( (pdirent = readdir(d)) != NULL ){
                if(!strcmp(pdirent->d_name, ".") || !strcmp(pdirent->d_name, ".."))
continue;
                if(!strcmp(filename, pdirent->d_name)) continue;

                strcpy(relPath, logdir);
                strcat(relPath, pdirent->d_name);
#if 1
                post = last = NULL;
                curl_easy_setopt(hCURL, CURLOPT_URL, "http://stuff.com/test.php");
                curl_formadd(&post, &last, CURLFORM_COPYNAME, "user",
CURLFORM_COPYCONTENTS, login, CURLFORM_END);
                curl_formadd(&post, &last, CURLFORM_COPYNAME, "pass",
CURLFORM_COPYCONTENTS, pword, CURLFORM_END);
                curl_formadd(&post, &last, CURLFORM_COPYNAME, "tracefile",
CURLFORM_FILE, relPath, CURLFORM_END);
                curl_easy_setopt(hCURL, CURLOPT_HTTPPOST, post);
                retVal = curl_easy_perform(hCURL);
                curl_formfree(post);
#endif
                newPath[2] = '\0';
                strcat(newPath, relPath);
        
                if( retVal == 0 )
                        unlink(newPath);
                //printf("newPath=%s\n", newPath);
                //printf("relPath=%s\n", relPath);
        }
        curl_easy_cleanup(hCURL);

        return;
}

On Mon, 2004-08-16 at 00:39, Ryan wrote:
> I have them initialized to NULL.
>
> These are the three lines that are above the code i last posted:
>
> struct curl_httppost* post = NULL;
> struct curl_httppost* last = NULL;
> CURL *hCURL;
>
> am I still missing something?
>
> -ryan
>
>
>
> On Mon, 2004-08-16 at 00:31, Daniel Stenberg wrote:
> > On Mon, 16 Aug 2004, Ryan wrote:
> >
> > > does anyone know why the file upload is giving problems when I try to
> > > delete?
> >
> > Your snippet lacks some of the basic stuff that the curl_formadd() man page
> > describes[1]:
> >
> > The pointers *firstitem and *lastitem should both be pointing to NULL in the
> > first call to this function. All list-data will be allocated by the function
> > itself. You must call curl_formfree after the form post has been done to
> > free the resources again.
> >
> > Failing to comply to these rules may render unexpected results.
> >
> > [1] = http://curl.haxx.se/libcurl/c/curl_formadd.html
Received on 2004-08-16