C++:如何使用libcurl检查FTP服务器上的目录是否存在

3

这个问题让我感到非常无助。我需要检查远程FTP服务器上是否存在一个目录。我的想法是:

//ls - lists the names of the files in the remote directory
string query = "ls /public_html/somefolder/";

//prepare to send
headers = curl_slist_append(headers, query.c_str());
curl_easy_setopt(curl, CURLOPT_QUOTE, headers); 

//send query to ftp server
res = curl_easy_perform(curl);

//check result
if(res == CURLE_OK) {
    cout << "FOLDER EXISTS";
} else {
    cout << "FOLDER DOESN'T EXIST";
}

当我检查res变量包含的内容时,输出为:

CURLE_QUOTE_ERROR (21).

有没有正确处理的想法?我已经在Google上搜索了很多。
1个回答

4
不要尝试使用 CURLOPT_QUOTE 来处理此操作。因为 LIST 是数据传输的一部分,所以应该在 CURLOPT_URL 中进行处理。
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp@ftp.gnu.org/pub/");
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
CURLcode res = curl_easy_perform(curl);
if(res == CURLE_OK) std::cout << "FOLDER EXISTS\n";
else std::cout << "FOLDER DOESN'T EXIST\n";

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接