cURL / Mailing Lists / curl-users / Single Mail

curl-users

Text files sent binary using libcurl

From: Carlson, John <jcarlson_at_tycoint.com>
Date: Tue, 21 Aug 2001 16:33:05 -0400

I am sending a text file from an AIX UNIX system to an FTP WEB server using
libcurl and C. They look like they are being sent as binary files, not
text.

When I look at the file, after bringing it back manually from the WEB server
to an NT system, it has no CR/LF at the end of the lines. So it looks like
it was sent binary to the WEB server.

Any text file, including that one, that I bring back to the AIX system,
using the program, is OK.

I've used several things in my program to force it to ASCII, but they
haven't helped.

The code I use for uploads follows. Any help would be appreciated.

    curl_handle = curl_easy_init();

    /* set URL & file to send */
    strcpy(buffer1,sessionData[TURL]);
    strcat(buffer1,"/");
    strcat(buffer1,sessionData[FILENAME]);
    strcat(buffer1,";type=A");

    curl_easy_setopt(curl_handle, CURLOPT_URL, buffer1);

    curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);
    curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1);

    /* determine number of bytes to send */
    bodyfile = (FILE*)fopen(sessionData[FILENAME],"r");
    if (bodyfile == NULL) {
      curl_easy_cleanup(curl_handle);
      return -1;
    }
    fseek (bodyfile, 0L, SEEK_END);
    lbytes = ftell (bodyfile);
    fclose(bodyfile);

    /* open the file for reading */
    bodyfile = (FILE*)fopen(sessionData[FILENAME],"r");
    if (bodyfile == NULL) {
      curl_easy_cleanup(curl_handle);
      return -1;
    }

    /* send all data to this function - needed w/CURLOPT_INFILE & win32 DLL
*/
    curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, read_data);

    curl_easy_setopt(curl_handle, CURLOPT_INFILE, bodyfile);
    curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE, lbytes);
    curl_easy_setopt(curl_handle, CURLOPT_TRANSFERTEXT, 1);

    strcpy(messageText,"");
    /* set readable error message */
    curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, messageText);

    /* upload */
    curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1);

    /* do it - send it! */
    returnCode=curl_easy_perform(curl_handle);

    fclose(bodyfile);

    curl_easy_cleanup(curl_handle);

John A. Carlson
SimplexGrinnell
JCarlson_at_TycoInt.com
Received on 2001-08-21