我正在使用C++和libcurl來執行SFTP/FTPS傳輸。在上傳文件之前,我需要檢查文件是否存在,而不是實際下載文件。使用libcurl檢查SFTP站點上是否存在文件
如果文件不存在,我遇到了以下問題:
//set up curlhandle for the public/private keys and whatever else first.
curl_easy_setopt(CurlHandle, CURLOPT_URL, "sftp://[email protected]: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.
如果我不使用CURLOPT_NOBODY,它的工作原理,我得到CURLE_REMOTE_FILE_NOT_FOUND。
但是,如果文件確實存在,它會被下載,這會浪費我時間,因爲我只是想知道它是否存在。
我錯過了其他任何技巧/選項?請注意,它也適用於ftps。
編輯:此錯誤與sftp發生。通過FTPS/FTP,我得到CURLE_FTP_COULDNT_RETR_FILE,我可以使用它。
您是否曾經解決過這個問題?我有同樣的問題。 – Lextar 2011-02-10 19:47:13