1

I'm using libcurl as part of my software for implementing an FTP client. One thing that I must do before sending files to the FTP server is to make a connectivity check by listing the the content of the target directory (to make sure I can connect and the directory exists) as was suggested to me in this question. The problem is I don't care about the output of the listing operation, all is care is whether the connectivity test passed or failed. In case it passed I get enormous amount of text which I'd like to discard. I'm using libcurl 7.33, however in 7.15 CURLOPT_MUTE was removed and I can't understand how to discard the listing output. Is there an alternative to CURLOPT_MUTE or any other idea how discard output from curl_easy_perform?

curl_easy_setopt(m_curl, CURLOPT_USERNAME, m_ftpUsername);
curl_easy_setopt(m_curl, CURLOPT_PASSWORD, m_ftpPassword);
curl_easy_setopt(m_curl, CURLOPT_URL, m_ftpUrl);
CURLcode res = curl_easy_perform(m_curl);
Community
  • 1
  • 1
e271p314
  • 3,841
  • 7
  • 36
  • 61

2 Answers2

1

Provide a CURLOPT_WRITEFUNCTION callback that simply ignores the data and returns the correct value!

BTW, MUTE never worked to "discard the listing output".

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
0

Define a callback function

size_t callbackFunction(char *ptr, size_t size, size_t nmemb, void *userdata)
{
    return size * nmemb;
}

And then

curl_easy_setopt(m_curl, CURLOPT_USERNAME, m_ftpUsername);
curl_easy_setopt(m_curl, CURLOPT_PASSWORD, m_ftpPassword);
curl_easy_setopt(m_curl, CURLOPT_URL, m_ftpUrl);
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, callbackFunction);
CURLcode res = curl_easy_perform(m_curl);
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, 0); // return using the default callback
e271p314
  • 3,841
  • 7
  • 36
  • 61