First time exploring this very useful library and am having a simple problem I'm unable to resolve, so would appreciate some help.
I'm doing a simple file download and have it working fine, except that I have to 'hardcode' the local filename, because otherwise I seem unable to have the download work. I'm basing this on the example found at http://curl.haxx.se/libcurl/c/ftpget.html. Rather than defining the local filename when declaring/initializing the ftpfile parameter, as shown in the example: int main(void) { CURL *curl; CURLcode res; struct FtpFile ftpfile={ "curl.tar.gz", /* name to store the file as if succesful */ NULL }; ... I am setting the filename inside my program as follows: int main(void) { CURL *curl; CURLcode res; struct FtpFile ftpfile; ftpfile.filename = "curl.tar.gz"; ftpfile.stream = NULL; This works fine, but if I want to instead assign a variable value to the filename, it doesn't work. I've tried various ways of getting a variable string into the filename of the struct FtpFile and am obviously missing something simple: char categoryName[32]; int categoryNumber; char buffer[128]; sprintf(buffer, "%s_%d.zip", categoryName, categoryNumber); ftpfile.filename = buffer; or strcpy(ftpfile.filename, buffer) Can someone please point out my error? A related question is how do I download a file using it's existing filename? The requested filename in the URL call allows me to use variable names, so is there an option to simply save the file locally using the same name without having to specify the name directly, which is what's causing my problem above? For example, sprintf(buffer, "ftp://%s/data/%d.zip", IPaddress, categoryNumber); curl_easy_setopt(curl, CURLOPT_URL, buffer); TIA ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
