views:

408

answers:

1

Hi guys,

I have a little doubt. I need to get a list of the files inside a specific directory on a SFTP server. I will use CUROPT_DIRLISTONLY in order to get just the names, but I'm not sure how to get them. This is the peace of code I have by now:

   string baseUrl(serverAddr + "/" + __destDir);
   curl_easy_setopt(anEasyHandle, CURLOPT_URL, (baseUrl).c_str());
   curl_easy_setopt(anEasyHandle, CURLOPT_VERBOSE,      1L);
   curl_easy_setopt(anEasyHandle, CURLOPT_DIRLISTONLY, 1);
   curl_easy_setopt(anEasyHandle, CURLOPT_QUOTE, commandList);

   curl_easy_perform(anEasyHandle);

   curl_easy_reset(anEasyHandle);

If I'm right, curl_easy_perform just returns an ERROR_CODE (success or error ir it applies), correct? So where can I get the files list?

If I run it on a terminal: curl -u user:pass sftp://server/path/ -l I get the list I want....

Any help would be appreciated.

Thanks in advance, George

+1  A: 

You need to create a "callback function" with the following signature:

size_t function( void *ptr, size_t size, size_t nmemb, void *stream);

You then call curl_easy_setopt to set the callback function as your CURLOPT_WRITEFUNCTION. Your function will be called for each chunk of data recieved from the remote server, which should be some form of directory listing.

Disclaimer: I have only read the documentation on this, not tried it.

Billy ONeal
A few moments after posting I found that same peace of information on the documentation. I'm trying and it seams to be working. Later I'll come back with better results. Thansk a lot.
George