libCurl:如何在不下载文件或目录列表的情况下发送QUOTE?

时间:2017-06-29 14:59:01

标签: c++ libcurl

我想删除sftp服务器上的文件。但是我遇到了这个问题,目录列表总是被下载,这可能是我服务器上的大量数据,并且需要花费很多时间在UMTS上。

这是我的代码:

const char* url = "sftp://user:pw@ip/home/user/myDir/";
const char* quote = "rm /home/user/myDir/sampleFile.jpg";

// prepare the QUOTE
struct curl_slist *slist=NULL;
slist = curl_slist_append(slist, quote);

CURLcode res;
res = curl_easy_setopt(mCurl, CURLOPT_URL, url);
res = curl_easy_setopt(mCurl, CURLOPT_QUOTE, slist);

res = curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, LIST_DIRECTORY_callback); // will download the directory listing => not wanted!
//res = curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, NULL); // does not work
res = curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, NULL);

// perform the commands
res = curl_easy_perform(mCurl);

curl_slist_free_all(slist);

mCurl是一个成员对象,仅初始化一次以重新使用其他调用的连接。这是初始化代码:

mCurl = curl_easy_init();

CURLcode res = curl_easy_setopt(mCurl, CURLOPT_DIRLISTONLY, 1); // 0 = no

mErrorBuffer.resize(CURL_ERROR_SIZE);
if(mErrorBuffer.size())
    mErrorBuffer[0] = 0;
res = curl_easy_setopt(mCurl, CURLOPT_ERRORBUFFER, mErrorBuffer.data());

如果我使用带有CURLOPT_WRITEFUNCTION选项的回调函数,它将下载目录列表。如果我将其设置为NULL,则会在res :中收到libCurl错误,无法将接收到的数据写入磁盘/应用程序"。

如何在不下载目录列表的情况下发送报价?我必须设置一些选项吗?我在文档中找不到任何内容。 也许我可以将URL更改为文件较少的文件夹,因此目录列表会更小,但我不希望在此处收到任何不必要的数据。

系统是Windows 7 32位,libCurl使用minGW编译。

0 个答案:

没有答案