在没有实际传输的情况下在libcurl中执行SFTP / FTP命令 [英] Executing SFTP/FTP command in libcurl without actual transfer
问题描述
我使用CURLOPT_QUOTE设置要执行的命令(实际上是文件删除),但是在执行后执行操作(并且它成功执行,文件被删除)curl试图上传或下载文件(基于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 是要求没有身体转移的关键。
Is it possible to execute SFTP command in libcurl without actual attempt of file transfer.
I set the command to execute (file deletion actually) using CURLOPT_QUOTE, but after executing the operation (and it executes successfully, file is deleted) curl is trying to upload or download file (based on CURLOPT_UPLOAD), so I get the CURLE_REMOTE_FILE_NOT_FOUND error error code.
What I tried so far - not setting the URL results in "malformed url error", setting CURLOPT_CONNECT_ONLY result in quote not executed as well. Is there any standard way?
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 is the key for asking that no "body" is to get transferred.
这篇关于在没有实际传输的情况下在libcurl中执行SFTP / FTP命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!