如果没有实际的文件传输尝试,是否可以在libcurl中执行SFTP命令?在没有实际传输的情况下在libcurl中执行SFTP/FTP命令
我将要执行的命令(删除文件实际上)使用CURLOPT_QUOTE,但在执行操作(和它成功执行,文件将被删除)卷曲试图上传或下载文件后(根据CURLOPT_UPLOAD),所以我得到CURLE_REMOTE_FILE_NOT_FOUND错误错误代码。
我到目前为止所尝试的 - 没有设置URL导致“格式错误的URL错误”,设置CURLOPT_CONNECT_ONLY导致报价不被执行。有没有标准的方法?
curl_global_init(CURL_GLOBAL_DEFAULT);
char temp[2000];
_snprintf(STRPARAM(temp),"%s://%s:%d/%s","sftp",m_url,m_port,a_ftpPath);
curl_easy_setopt(m_curl, CURLOPT_URL,temp);
_snprintf(STRPARAM(temp),"%s:%s",m_name,m_pass);
curl_easy_setopt(m_curl, CURLOPT_USERPWD, temp);
curl_easy_setopt(m_curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PASSWORD);
curl_easy_setopt(m_curl, CURLOPT_UPLOAD, 0L);
curl_easy_setopt(m_curl, CURLOPT_READFUNCTION, NULL);
curl_easy_setopt(m_curl, CURLOPT_NOBODY, 1L);
curl_easy_setopt(m_curl, CURLOPT_HEADER, 1L);
struct curl_slist *headerlist=NULL;
_snprintf(STRPARAM(temp),"rm /%s",a_ftpPath);
headerlist = curl_slist_append(headerlist, temp);
curl_easy_setopt(m_curl, CURLOPT_QUOTE, headerlist);
m_res = curl_easy_perform(m_curl);
curl_easy_setopt(m_curl, CURLOPT_QUOTE, NULL);
curl_easy_setopt(m_curl, CURLOPT_HEADER, 0L);
curl_easy_setopt(m_curl, CURLOPT_NOBODY, 0L);
curl_slist_free_all (headerlist);
curl_global_cleanup();
随着CURLOPT_NOBODY集libcurl的报价不执行,以及,文件保持不变 – elevener
这可能是要考虑的一个bug ...... –
看起来,他们认为这是正常的,报价没有传输是不可能的:(Curl faq http://curl.haxx.se/docs/faq.html#How_do_I_tell_curl_to_run_custom不得不绕过该问题 – elevener