看网上 demo, 都是将文件信息写道文件里, 然后逐行读取文件.
稍微改了下, 增加了递归遍历.
最后一个字符为 '/' 的是文件夹, 否则是文件.
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include <curl/curl.h>
//定义根目录
#define root_dictory "ftp://192.168.1.194:21"
int get_ftp_file_list(std::string ftp_dictory, std::vector<std::string> & file_list)
{
/* local file name to store the file as */
FILE * ftpfile = fopen("ftplist", "wb");
CURL * curl = curl_easy_init();
if (curl)
{
/* get a file listing from sunet */
curl_easy_setopt(curl, CURLOPT_URL, ftp_dictory.c_str());
/*user & pwd*/
curl_easy_setopt(curl, CURLOPT_USERPWD, "ftpadmin:ftpmima");
/*ftp file info will be write in this file*/
curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile);
/*run the opt*/
CURLcode res = curl_easy_perform(curl);
/* check for errors */
if (res != CURLE_