Search code examples
c++ftpwxwidgetslibcurl

LibCurl: Changing CWD


I'm migrating from wxFTP that comes with wxWidgets to libcurl. I have mad a way to connect and get all Directories and file at / directory by simply providing URL. Now I need to change to another directory (let say /public_html/mysite). I cannot do this with libcurl.

I cannot believe that its so hard to do it in libcurl so I'm inclined to conclusion that I miss something here. My relevant Code is shown below and all I have is relative Paths like /www not ftp URL like ftp://someurl.com/www/

Sorry if its something obvious am very new to libcurl and have worked for many hours already unsuccessful.

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);

Solution

  • It was my mistake ain a code that ended sending URLs with format ftp://ftp.hosanna.site40.net:21/public_html So I changed to use PORT in easy setopt.

    So its not curl's problem but mine (though very subtle to me) Also make sure that all the directories ends with / or libray will interpret them as files.

    eg

    ftp://ftp.hosanna.site40.net/public_html //interpreted as file
    ftp://ftp.hosanna.site40.net/public_html/ //interpreted as directory