Search…
README
How to read this book
The cURL project
Network and protocols
Install curl
Source code
Build curl
Command line basics
Using curl
HTTP with curl
FTP with curl
Using libcurl
Header files
Easy handle
Drive transfers
Connection reuse
Callbacks
Cleanup
Name resolving
Proxies
Post transfer info
Share data between handles
URL API
Header API
API compatibility
--libcurl
Global initialization
multi-threading
curl easy options
CURLcode return codes
Verbose operations
Caches
libcurl examples
Get a simple HTTP page
Get a response into memory
Submit a login form over HTTP
Get an FTP directory listing
Non-blocking HTTP form-post
for C++ programmers
HTTP with libcurl
Bindings
libcurl internals
Index
Powered By
GitBook
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_global_init(CURL_GLOBAL_DEFAULT);
​
curl = curl_easy_init();
if(curl) {
/*
* Make the URL end with a trailing slash!
*/
curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/");
​
res = curl_easy_perform(curl);
​
/* always cleanup */
curl_easy_cleanup(curl);
​
if(CURLE_OK != res) {
/* we failed */
fprintf(stderr, "curl told us %d\n", res);
}
}
​
curl_global_cleanup();
​
return 0;
}
Previous
Submit a login form over HTTP
Next
Non-blocking HTTP form-post
Last modified
8mo ago
Export as PDF
Copy link
Edit on GitHub