cURL / Mailing Lists / curl-library / Single Mail


RE: Setting Local Directory for an ftpget

From: SuperWare Support <>
Date: Tue, 20 Dec 2011 08:14:33 -0500

Please stop top-posting.

>> Note that I am using the wildcard ftpget example.

>Oh. It makes thing slightly different, but not much.

>> Perhaps it varies from the regular ftp example. I need to know how to
>> set a directory name in front of the filename when opening the file.

>When that callback is called, you know what URL you used - and you know the
particular single file name since that is set within the fileinfo struct.

>Your code simple needs to figure out what directory name to prepend to the
file names you get.
[David Johns] Okay - I figured out a couple of things. I ended up using a
global variable I had available to give the callback function access to the
directory I needed to save the files in locally. I also figured out,
however, that the callback_data struct is purposefully not defined in
libcurl itself so that calling applications can place in that struct
whatever information they need to have in the callback functions - very
nicely done! I like how you did that. I could have used this to pass the
directory into the callback functions as well, but since I had the global
variable already available this wasn't necessary

>> As I tried to explain, but perhaps didn't do well was that I need to
>> be able to specify that directory at runtime rather than compile it into
the code.

The same general idea applies in this callback though. It gives you
information, you need to handle it and convert it to what you think is

Also note that the wildcard thing is only listing the files, it doesn't
actually transfer their contents. You probably want to store all files in a
list/array somewhere and after you've received the entire list you ask for
the files you'd like to get.
[David Johns] The source file ftp-wildcard.c does actually get the files.

Now I am faced with one more challenge. I have it successfully getting the
files, but am looking if there is an easy way to rename all the files it has
just downloaded without starting from scratch to add all the necessary
options - url, username, password, etc... What I tried to do is add a
curl_slist to the callback_data struct and in the file_is_comming callback I
append RNFR and RNTO pairs to build a command list that could be executed.
I tried issuing a curl_easy_setopt(curl, CURLOPT_POSTQUOTE, data.headerlist)
before running the commands which get the files in hopes that libcurl would
take the curl_slist headerlist list of commands as it exists when it is
ready to run the commands, but apparently it takes it at the point where you
set the CURLOPT_POSTQUOTE, which is empty at that time. Is there an easy
way to take that list of commands, the url, the ssl settings and basically
everything except the callbacks and other things that drive downloading the
files the first pass through?


List admin:
List admin:
Received on 2011-12-20