LibCurl: Changing CWD
LibCurl: Changing CWD
我正在从wxWidgets附带的wxFTP迁移到libcurl。我有一种疯狂的方法,只需提供URL,就可以连接并获取/directory中的所有目录和文件。现在我需要更改到另一个目录(比如/public_html/mysite)。我不能用libcurl做这件事。
我不敢相信在libcurl中这么难做到,所以我倾向于得出这样的结论:我错过了一些东西。我的相关代码如下所示,我所拥有的只是像/www这样的相对路径,而不是像ftp这样的URLftp://someurl.com/www/
很抱歉,如果这是显而易见的事情。我对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);
这是我的错误,因为一个代码结束了以ftp://ftp.hosanna.site40.net:21/public_html
格式发送URL,所以我改为在easy-setopt中使用PORT。
所以这不是curl的问题,而是我的问题(尽管对我来说很微妙)还要确保所有的目录都以/或libray结尾,并将它们解释为文件。
例如
ftp://ftp.hosanna.site40.net/public_html //interpreted as file
ftp://ftp.hosanna.site40.net/public_html/ //interpreted as directory