I am using C ++ with libcurl to transmit SFTP / FTPS. Before downloading the file, I need to check if the file exists without downloading it.
If the file does not exist, I encounter the following problems:
//set up curlhandle for the public/private keys and whatever else first.
curl_easy_setopt(CurlHandle, CURLOPT_URL, "sftp://user@pass:host/nonexistent-file");
curl_easy_setopt(CurlHandle, CURLOPT_NOBODY, 1);
curl_easy_setopt(CurlHandle, CURLOPT_FILETIME, 1);
int result = curl_easy_perform(CurlHandle);
//result is CURLE_OK, not CURLE_REMOTE_FILE_NOT_FOUND
//using curl_easy_getinfo to get the file time will return -1 for filetime, regardless
//if the file is there or not.
If I do not use CURLOPT_NOBODY, it works, I get CURLE_REMOTE_FILE_NOT_FOUND.
However, if the file exists, it is uploaded, which spends time on me, since I just want to know if it is there or not.
Any other methods / options that I am missing? Please note that it should work for ftps as well.
Edit: this error occurs using sftp. With FTPS / FTP, I get CURLE_FTP_COULDNT_RETR_FILE that I can work with.