我试图从SFTP服务器获取带有libcurl的C ++目录列表,但是我得到了错误79 - SSH层错误。
有大约8000个文件要列出,我有时会在5分钟后收到错误,有时候会在10分钟后收到错误。它在仅包含少量文件(< 300)的目录上正常工作。
size_t WriteMemoryCallback(void* buffer, size_t size, size_t nmemb, void* memory)
{
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)memory;
mem->memory = (char*)realloc(mem->memory, mem->size + realsize + 1);
if(mem->memory == NULL) {
return 0;
}
memcpy(&(mem->memory[mem->size]), buffer, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
return realsize;
}
...
struct MemoryStruct chunk;
chunk.memory = (char*)malloc(1);
chunk.size = 0;
curl_easy_setopt(m_curl, CURLOPT_URL, "sftp://username@hostname/dir");
curl_easy_setopt(m_curl, CURLOPT_PORT, 22);
curl_easy_setopt(m_curl, CURLOPT_TRANSFERTEXT, 0);
curl_easy_setopt(m_curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PUBLICKEY);
curl_easy_setopt(m_curl, CURLOPT_SSH_PUBLIC_KEYFILE, path);
curl_easy_setopt(m_curl, CURLOPT_SSH_PRIVATE_KEYFILE, path);
curl_easy_setopt(m_curl, CURLOPT_DIRLISTONLY, 1);
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, (void*)&chunk);
m_errorCode = curl_easy_perform(m_curl);
我使用libcurl v4.3.0和libssh2 v1.4.3。我在命令行工具上遇到了同样的问题。但是不要在详细模式下获得更多信息。
有什么想法吗? 感谢