How do I use libcurl to printf a remote FTP directory listing?


I think I'm supposed to use CURLOPT_DIRLISTONLY but I'm not really sure how to proceed.

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DIRLISTONLY, long listonly);

I'm not sure how to make the call to actually print the list.


Enabling the CURLOPT_DIRLISTONLY option for FTP has the effect of retrieving only file names instead of file details (e.g. file size, date, etc.) basically as the difference between using a plain ls (only names) or a ls -l (listing with details) on UNIX. At the FTP protocol level, enabling CURLOPT_DIRLISTONLY will make libcurl issue a NLST command rather than a LIST. Then to get the directory listing you do the same as a file transfer, with the difference that your ftp:// URL will point to a directory (and not to a file). The contents of that transfer will be your directory listing.

To display the directory listing, rather than saving it to a file, you can use the CURLOPT_WRITEFUNCTION option to have libcurl call a callback function you supply for every block of data. That function only needs to fwrite the data to stdout to display it. It should look something like this:

void write_callback(void* data, size_t size, size_t nmemb, void* ptr) { fwrite(data, size, nmemb, stdout); } int main() { // ... curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_callback); // ... ret = curl_easy_perform(handle); }


  • Bash - how to preserve newline in sed command output?
  • App crashes on iPhone but not on simulator
  • Why is System.in declared as nullInputStream() instead of null?
  • Memory Leak UITableView
  • Sorting list of dictionaries according to specific order
  • type “e” does not exist , Redshift through Postgresql connector in php codeigniter
  • channels without channel layer or any other free hosting
  • How to do handle login-logoff
  • Contact us email sending is not working in codeigniter php
  • Rezize HTML Canvas size after transformed operation
  • Does Tomcat cache compiled JSP pages in memory if scratchdir is read-only?
  • Why context.Wait in StartAsync didn't stop the dialog
  • How do you save a Linq object if you don't have its data context?
  • On Woocommerce order complete, activate woosensei course
  • Eloquent Javascript: Can't understand how the number value is determined in the sum function
  • How to run python3.7 based flask web api on azure
  • Starting Bootstrap tour with a button after ending tour once
  • How to set title name of the pdf. While viewing the Document(New Tab)
  • SCNText Not Displaying
  • Extract the data specified in brackets '[ ]' from a string message in python
  • MySQL ordering a date range to the beginning, then ordering everything else by other criteria
  • JavaFX Embed Custom Font Not Working
  • Filtering out choiceless polls in the Django tutorial causes polls in the index to duplicate
  • yii rewrite url with many sub categories
  • internal javascript not works in angular2
  • dmtracedump doesn't work, HELP!
  • Excel Reverse Match
  • separate tokens in batch file
  • LINQ to populate treeview based upon grouping
  • Set WebClient.Builder.exchangeStrategies() without losing Spring Jackson configuration
  • Create an average of multiple excel chart without the data source
  • How convert html to BBcode in C#
  • Google Spreadsheet Script to Blink a range of Cells
  • C++ STL stack pop operation giving segmentation fault
  • how to run ejabberd with Erlang on Heroku?
  • How to use Streams api peek() function and make it work?
  • Change cell value based on cell color in google spreadsheet
  • How do I add a mouse over tooltip to an Image using .DrawImage()
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?