c++ - 使用 libcurl 下载目录中的所有文件

标签 c++ download libcurl ftps

我是 libcurl 的新手,找到了一种从 ftp 服务器下载单个文件的方法。现在我的要求是下载目录中的所有文件,我猜 libcurl 不支持它。请在 libcurl 上建议如何下载目录中的所有文件,或者是否有任何其他类似于 libcurl 的库?

提前致谢。

最佳答案

这是一段示例代码。

static size_t GetFilesList_response(void *ptr, size_t size, size_t nmemb, void *data)
{
    FILE *writehere = (FILE *)data;
    return fwrite(ptr, size, nmemb, writehere);
}

bool FTPWithcURL::GetFilesList(char* tempFile)
{
    CURL *curl;
    CURLcode res;
    FILE *ftpfile;

    /* local file name to store the file as */
    ftpfile = fopen(tempFile, "wb"); /* b is binary, needed on win32 */ 

    curl = curl_easy_init();
    if(curl) 
    {
        curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com");
        curl_easy_setopt(curl, CURLOPT_USERPWD, "username:password");
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile);
        // added to @Tombart suggestion
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, GetFilesList_response);
        curl_easy_setopt(curl, CURLOPT_DIRLISTONLY, 1);

        res = curl_easy_perform(curl);

        curl_easy_cleanup(curl);
    }

    fclose(ftpfile); //


    if(CURLE_OK != res) 
        return false;

    return true;
}

关于c++ - 使用 libcurl 下载目录中的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2162022/

相关文章:

c++ - QTabWidget 选项卡上下文菜单

c++ - C/C++ : A weird library function declaration

c++ - 当我们尝试使用 istream::getline() 和 std::getline() 提取文件中出现 `eof` 字符的行时,实际会发生什么

Java - 从 OneDrive 公共(public)文件夹下载

c - 在 C 项目中包含 libcurl

python - Pybind11:在C++函数中返回大型数组会显着增加python中的计算时间

Python:从 FTP 服务器下载文件

php - 通过 php 下载 Google Play APK

c++ - curl 与 Visual Studio 2013

c++ - libcurl + openssl 无法下载大于 2GB 的文件