curl-library
ftp upload results in (nil) filename
Date: Mon, 3 Feb 2003 10:27:13 -0500
I'm trying to use libcurl to upload some files in a C++ program (no
wrapper, just straight libcurl). I'm feeding curl data straight from memory
via the CURLOPT_READFUNCTION and CURLOPT_READDATA options. While the
connect and transfer are fine, curl always uploads the file as (nil). I see
no way to actually set the remote filename through options either, but I
could be missing an option.
Speaking of which, the current curl_easy_setopt page on the web
(http://curl.sourceforge.net/libcurl/c/curl_easy_setopt.html - didn't check
SE or other versions) is missing sections due to bad HTML - notably
CURLOPT_READDATA and anything else near a "NOTE" section. The man pages are
fine though.
Here's a sample C program that replicates the behavior. I'm on AIX 4.3.3
using xlc as a compiler. libcurl was compiled on this box with gcc 3.2.1.
You'll need to change the destURL and userpwd values as needed, obviously.
Thanks for any help.
--- begin
ftptest.c -----------------------------------------------------------------
---- #include <stdio.h> #include <stdlib.h> #include <curl.h> size_t dataSize; size_t readFtpData(void* ptr, size_t size, size_t nmemb, void* stream) { size_t total = size * nmemb; if (total > dataSize) { total = dataSize; } if (total > 0) { memcpy(ptr, stream, total); memcpy(stream, ((char*)stream)+total, dataSize-total); dataSize -= total; } return total; } int main(int argc, char* argv[]) { char* destURL = "ftp://yourhosthere/tmp/test/"; char* userpwd = "user:passwd"; char* data = "asdlfjsdjfksjadkfjsdkjf;jsdkl;jfl;sdghhgadshfohyfpoyiopqypwoe\n"; CURL* myCurl = curl_easy_init(); curl_easy_setopt(myCurl, CURLOPT_VERBOSE, 1); curl_easy_setopt(myCurl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(myCurl, CURLOPT_URL, destURL); curl_easy_setopt(myCurl, CURLOPT_USERPWD, userpwd); curl_easy_setopt(myCurl, CURLOPT_INFILESIZE, strlen(data)); curl_easy_setopt(myCurl, CURLOPT_UPLOAD, 1); curl_easy_setopt(myCurl, CURLOPT_READFUNCTION, readFtpData); curl_easy_setopt(myCurl, CURLOPT_READDATA, data); dataSize = strlen(data); curl_easy_perform(myCurl); curl_easy_cleanup(myCurl); return 0; } --- end ftptest.c ----------------------------------------------------------------- ---- ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.comReceived on 2003-02-03