Search…
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.
1
#include <curl/curl.h>
2
3
int main(void)
4
{
5
CURL *curl;
6
CURLcode res;
7
8
curl_global_init(CURL_GLOBAL_DEFAULT);
9
10
curl = curl_easy_init();
11
if(curl) {
12
/*
13
* Make the URL end with a trailing slash!
14
*/
15
curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/");
16
17
res = curl_easy_perform(curl);
18
19
/* always cleanup */
20
curl_easy_cleanup(curl);
21
22
if(CURLE_OK != res) {
23
/* we failed */
24
fprintf(stderr, "curl told us %d\n", res);
25
}
26
}
27
28
curl_global_cleanup();
29
30
return 0;
31
}
Copied!
Last modified 10d ago
Export as PDF
Copy link
Edit on GitHub