C++:如何使用libcurl检查FTP服务器上是否存在目录
C++: How to check if a directory exists on an FTP server using libcurl
我对此束手无策。我需要检查远程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)。
关于如何正确地做到这一点,有什么想法吗?我在谷歌上搜索了很多次。
不要尝试为此使用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 EXISTSn";
else std::cout << "FOLDER DOESN'T EXISTn";
相关文章:
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 如何检查QList中是否存在值
- 根据某个函数是否存在启用模板
- 地图计数确实很重要,或者只是检查是否存在
- C++中是否存在 std::conditional 的懒惰等价物?
- 无论如何,我可以确定构造函数是否存在吗?
- COM :是否可以查看是否存在对我的某个 COM 对象的进程外引用?我可以释放它吗?
- 堆分配的对象是否存在永不为空的唯一所有者?
- 扩展类中的可选 vir 函数,测试它在运行时是否存在
- 模板化检查是否存在带有参数列表的类成员函数?
- 是否存在包含负号的isdigit函数(过载)
- 如何巧妙地编写两个函数——一个用于检查是否存在解决方案,另一个用于获取所有解决方案
- 检查编译时是否存在静态函数
- 向量是否存在行主要形式?
- 检查 TinyXML 中的元素是否存在
- 检测是否存在具有 C++17 的类成员
- 虚拟继承中是否存在多重继承?
- 我遇到了这个代码片段,不明白. 它递归检查 C++ 字符串中是否存在大写字符
- std::weak_ptr 和相应的 std::shared_ptr 之间是否存在数据竞争?
- 是否存在用于 C 或 C++ 中常见数学运算(例如最小值、最大值和平均值)的可导入库?