Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy this is not working ? libcurl & c++
    primarykey
    data
    text
    <p>I am new to libcurl and am trying to get filelist from a server using ftp, going through the examples and some other posts here, I have come up with the following code. But when I run it, it returns error message :</p> <blockquote> <p>Failed writing body (4294967295 != 129)</p> </blockquote> <p>in the error string set by CURLOPT_ERRORBUFFER. The <code>curl_easy_strerror( res )</code> returns:</p> <blockquote> <p>Failed writing received data to disk/application</p> </blockquote> <pre><code>struct FtpFile { const char *filename; FILE *stream; }; static size_t fileWrite( void *buffer, size_t size, size_t nmemb, void *stream ) { struct FtpFile *out=(struct FtpFile *)stream; if(out &amp;&amp; !out-&gt;stream) { out-&gt;stream=fopen(out-&gt;filename, "wb"); if(!out-&gt;stream) { cout &lt;&lt; out-&gt;filename &lt;&lt; " open failure [fileWrite] " &lt;&lt; endl; return -1; } } size_t written = fwrite(buffer, size, nmemb, out-&gt;stream); cout &lt;&lt; written &lt;&lt; endl; if(written &lt;= 0) cout &lt;&lt; "Nothing written : " &lt;&lt; written; return written; } void getFileList( const char* url, const char* fname ) { CURL *curl; CURLcode res; FILE *ftpfile; const char *errmsg; ftpfile = fopen(fname, "wb"); if ( ftpfile == NULL ) { cout &lt;&lt; fname &lt;&lt; " open failure [getFileList] " &lt;&lt; endl ; return; } curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fileWrite); curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg); curl_easy_setopt(curl, CURLOPT_USERNAME, "username"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "password"); curl_easy_setopt(curl, CURLOPT_FTPLISTONLY,TRUE); res = curl_easy_perform(curl); if(res != CURLE_OK) { fprintf( stderr, "curl_easy_perform() failed: %s\nError Message: %s\n", curl_easy_strerror( res ), errmsg ); } curl_easy_cleanup(curl); } fclose(ftpfile); } int main(int argc, char *argv[]) { getFileList( "ftp://ftp.example.com/public/somefolder/", "file-list.txt" ); system("PAUSE"); return EXIT_SUCCESS; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload