Get an FTP directory listing

This example just fetches the FTP directory output from the given URL and sends it to stdout. The trailing slash in the URL is what makes libcurl treat it as a directory.

#include <curl/curl.h>

int main(void)
  CURL *curl;
  CURLcode res;


  curl = curl_easy_init();
  if(curl) {
     * Make the URL end with a trailing slash
    curl_easy_setopt(curl, CURLOPT_URL, "");

    res = curl_easy_perform(curl);

    /* always cleanup */

    if(CURLE_OK != res) {
      /* we failed */
      fprintf(stderr, "curl told us %d\n", res);


  return 0;