curl-library
Re: Variable filename in FTP download
Date: Fri, 5 Nov 2010 09:57:56 +0100 (CET)
On Thu, 4 Nov 2010, Lucas wrote:
> 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.
This problem seems to be entirely within your program and C programming, and
isn't really a libcurl issue...
> 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;
This should work, assuming that buffer is still around when you want to read
out the file name. And beware of buffer overflow.
> strcpy(ftpfile.filename, buffer)
That's probably not what you want.
> A related question is how do I download a file using it's existing filename?
Well, you give libcurl the full URL so surely you know the 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?
No, there's no such magic option.
-- / daniel.haxx.se ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.htmlReceived on 2010-11-05