【发布时间】:2023-12-04 15:58:01
【问题描述】:
我正在从 wxWidgets 附带的 wxFTP 迁移到 libcurl。我有一种方法可以通过简单地提供 URL 来连接并获取 / 目录中的所有目录和文件。现在我需要切换到另一个目录(比如说 /public_html/mysite)。我不能用 libcurl 做到这一点。
我不敢相信在 libcurl 中做到这一点是如此困难,所以我倾向于得出结论,我在这里错过了一些东西。我的相关代码如下所示,我所拥有的只是像 /www 这样的相对路径,而不是像 ftp://someurl.com/www/ 这样的 ftp URL
很抱歉,如果它对 libcurl 来说是非常新的东西并且已经工作了很多小时已经不成功了。
CURL* handle = curl_easy_init();
SetHandleOptions(handle); //set options
CURLcode res;
if(handle)
{
wxString command ="CWD "+path;
curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST , command.ToStdString().c_str());
res = curl_easy_perform(handle);
if(res==CURLE_OK)
{
wxString str(curl_easy_strerror(res));
SendMessage(str);
curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST , "MLSD");
res = curl_easy_perform(handle);
if(res==CURLE_OK)
{
wxString str(curl_easy_strerror(res));
SendMessage(str);
}
else
{
//send error message
wxString str(curl_easy_strerror(res));
SendMessage(str);
}
}
else
{
//send error message
wxString str(curl_easy_strerror(res));
SendMessage(str);
}
}
curl_easy_cleanup(handle);
【问题讨论】: