download function with libcurl, but it works incomplete [closed]Http status code with libcurl?How do function pointers in C work?C libcurl get output into a stringWhy do we need virtual functions in C++?Typedef function pointer?'Unresolved external symbol' errorsC2664 Cannot Convert ParameterlibCurl x64 build problems Visual Studio 2013 (x64) Visual Studio & CMakeLibcurl: image is damaged when using fstream::write instead of fwriteWrite callback for https in libcurl on windows

How to continue a line in Latex in math mode?

What are these circular spots on these Ariane V SRB nozzles?

What could prevent players from leaving an island?

Did Captain America make out with his niece?

Was Richard I's imprisonment by Leopold of Austria justified?

Validation and verification of mathematical models

Best way to explain to my boss that I cannot attend a team summit because it is on Rosh Hashana or any other Jewish Holiday

How does current flow in this path when all points are at the same potential?

If someone else uploads my GPL'd code to Github without my permission, is that a copyright violation?

Is it double speak?

Responding to Plague Engineer

Traveling from Germany to other countries by train?

Did Apollo leave poop on the moon?

Can I enter a rental property without giving notice if I'm afraid a tenant may be hurt?

How to realistically deal with a shield user?

How do I get the =LEFT function in excel, to also take the number zero as the first number?

Colleagues speaking another language and it impacts work

How to help new students accept function notation

Why does putting a dot after the URL remove login information?

Repeated! Factorials!

Secure my password from unsafe servers

Print only the last three columns from file

Does this put me at risk for identity theft?

Count number of occurences of particular numbers in list



download function with libcurl, but it works incomplete [closed]


Http status code with libcurl?How do function pointers in C work?C libcurl get output into a stringWhy do we need virtual functions in C++?Typedef function pointer?'Unresolved external symbol' errorsC2664 Cannot Convert ParameterlibCurl x64 build problems Visual Studio 2013 (x64) Visual Studio & CMakeLibcurl: image is damaged when using fstream::write instead of fwriteWrite callback for https in libcurl on windows






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Greetings everyone read this topic, my platform is win32. And I'm using libcurl with a problem.



My goal is to coding with libcurl for a download program, which it includes requesting a url to download a file, saving the file locally(fwrite), showing the progress bar while downloading.



The Problem is it can download the very small file well but when requesting a larger file like 30MB, it stops before it's done.



How can I debug this program to work well with any size of files?



I'm not familiar with libcurl, any simple detail could help. Can I have either answer of how curl_easy series works to call multiple callback functions, improper coding of either of the two callback functions, or some missing rules from libcurl?
Feel free to answer me anything.



Things I've tried:



1.I've tried re-compiling versions of libcurl. Now I'm using libcurl-7.64 compiled with "WITH_SSL=static".



2.I've tried many sites, finding the clue: the sites for very small(like 80kb) file will be downloaded completely with the progress bar. But larger file(like 30Mb) will be incomplete. One of my guess is it stopped from some transfer problem since the file is larger.



codes:



static FILE * fp;

static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)



size_t nWrite = fwrite(ptr, size, nmemb, fp);

return nWrite;



static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)



(void)ultotal;
(void)ulnow;
int totaldotz = 40;

double fractiondownloaded = (double)dlnow / (double)dltotal;
int dotz = (int)(fractiondownloaded * totaldotz);

printf("%3.0f%% [", fractiondownloaded * 100); //print the number percentage of the progress

int i = 0;
for (; i < dotz; i++) //print "=" to show progress
printf("=");


for (; i < totaldotz; i++) //print space to occupy the rest
printf(" ");

printf("]r");
fflush(stdout);

return 0;


int download_function(CURL *curl,const char * url, const char * path)



curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
fopen_s(&fp, path, "ab+");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);
char * error = NULL;
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
CURLcode retcCode = curl_easy_perform(curl);
fclose(fp);
const char* pError = curl_easy_strerror(retcCode);
if (curl)
curl_easy_cleanup(curl);

return 0;











share|improve this question
















closed as off-topic by Basile Starynkevitch, Jodocus, Kamiccolo, Umair, Rekshino Mar 27 at 15:07


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – Basile Starynkevitch, Jodocus, Kamiccolo, Umair, Rekshino
If this question can be reworded to fit the rules in the help center, please edit the question.

















  • Welcome to SO. Your question should provide an minimal reproducible example. Without one, it is incomplete, and will eventually get closed. Please edit your question to improve it

    – Basile Starynkevitch
    Mar 27 at 5:28












  • Read also How to debug small programs and read much more about the HTTP protocol. You may want to recompile libcurl with debugging options (e.g. with gcc -g)

    – Basile Starynkevitch
    Mar 27 at 5:30







  • 1





    please print pError to look what is the reason, it is your set timeout 3s expired? curl_easy_setopt(curl,CURLOPT_TIMEOUT,3L); Is it normal after removal?

    – ccxxshow
    Mar 27 at 6:49


















0















Greetings everyone read this topic, my platform is win32. And I'm using libcurl with a problem.



My goal is to coding with libcurl for a download program, which it includes requesting a url to download a file, saving the file locally(fwrite), showing the progress bar while downloading.



The Problem is it can download the very small file well but when requesting a larger file like 30MB, it stops before it's done.



How can I debug this program to work well with any size of files?



I'm not familiar with libcurl, any simple detail could help. Can I have either answer of how curl_easy series works to call multiple callback functions, improper coding of either of the two callback functions, or some missing rules from libcurl?
Feel free to answer me anything.



Things I've tried:



1.I've tried re-compiling versions of libcurl. Now I'm using libcurl-7.64 compiled with "WITH_SSL=static".



2.I've tried many sites, finding the clue: the sites for very small(like 80kb) file will be downloaded completely with the progress bar. But larger file(like 30Mb) will be incomplete. One of my guess is it stopped from some transfer problem since the file is larger.



codes:



static FILE * fp;

static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)



size_t nWrite = fwrite(ptr, size, nmemb, fp);

return nWrite;



static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)



(void)ultotal;
(void)ulnow;
int totaldotz = 40;

double fractiondownloaded = (double)dlnow / (double)dltotal;
int dotz = (int)(fractiondownloaded * totaldotz);

printf("%3.0f%% [", fractiondownloaded * 100); //print the number percentage of the progress

int i = 0;
for (; i < dotz; i++) //print "=" to show progress
printf("=");


for (; i < totaldotz; i++) //print space to occupy the rest
printf(" ");

printf("]r");
fflush(stdout);

return 0;


int download_function(CURL *curl,const char * url, const char * path)



curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
fopen_s(&fp, path, "ab+");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);
char * error = NULL;
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
CURLcode retcCode = curl_easy_perform(curl);
fclose(fp);
const char* pError = curl_easy_strerror(retcCode);
if (curl)
curl_easy_cleanup(curl);

return 0;











share|improve this question
















closed as off-topic by Basile Starynkevitch, Jodocus, Kamiccolo, Umair, Rekshino Mar 27 at 15:07


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – Basile Starynkevitch, Jodocus, Kamiccolo, Umair, Rekshino
If this question can be reworded to fit the rules in the help center, please edit the question.

















  • Welcome to SO. Your question should provide an minimal reproducible example. Without one, it is incomplete, and will eventually get closed. Please edit your question to improve it

    – Basile Starynkevitch
    Mar 27 at 5:28












  • Read also How to debug small programs and read much more about the HTTP protocol. You may want to recompile libcurl with debugging options (e.g. with gcc -g)

    – Basile Starynkevitch
    Mar 27 at 5:30







  • 1





    please print pError to look what is the reason, it is your set timeout 3s expired? curl_easy_setopt(curl,CURLOPT_TIMEOUT,3L); Is it normal after removal?

    – ccxxshow
    Mar 27 at 6:49














0












0








0








Greetings everyone read this topic, my platform is win32. And I'm using libcurl with a problem.



My goal is to coding with libcurl for a download program, which it includes requesting a url to download a file, saving the file locally(fwrite), showing the progress bar while downloading.



The Problem is it can download the very small file well but when requesting a larger file like 30MB, it stops before it's done.



How can I debug this program to work well with any size of files?



I'm not familiar with libcurl, any simple detail could help. Can I have either answer of how curl_easy series works to call multiple callback functions, improper coding of either of the two callback functions, or some missing rules from libcurl?
Feel free to answer me anything.



Things I've tried:



1.I've tried re-compiling versions of libcurl. Now I'm using libcurl-7.64 compiled with "WITH_SSL=static".



2.I've tried many sites, finding the clue: the sites for very small(like 80kb) file will be downloaded completely with the progress bar. But larger file(like 30Mb) will be incomplete. One of my guess is it stopped from some transfer problem since the file is larger.



codes:



static FILE * fp;

static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)



size_t nWrite = fwrite(ptr, size, nmemb, fp);

return nWrite;



static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)



(void)ultotal;
(void)ulnow;
int totaldotz = 40;

double fractiondownloaded = (double)dlnow / (double)dltotal;
int dotz = (int)(fractiondownloaded * totaldotz);

printf("%3.0f%% [", fractiondownloaded * 100); //print the number percentage of the progress

int i = 0;
for (; i < dotz; i++) //print "=" to show progress
printf("=");


for (; i < totaldotz; i++) //print space to occupy the rest
printf(" ");

printf("]r");
fflush(stdout);

return 0;


int download_function(CURL *curl,const char * url, const char * path)



curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
fopen_s(&fp, path, "ab+");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);
char * error = NULL;
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
CURLcode retcCode = curl_easy_perform(curl);
fclose(fp);
const char* pError = curl_easy_strerror(retcCode);
if (curl)
curl_easy_cleanup(curl);

return 0;











share|improve this question
















Greetings everyone read this topic, my platform is win32. And I'm using libcurl with a problem.



My goal is to coding with libcurl for a download program, which it includes requesting a url to download a file, saving the file locally(fwrite), showing the progress bar while downloading.



The Problem is it can download the very small file well but when requesting a larger file like 30MB, it stops before it's done.



How can I debug this program to work well with any size of files?



I'm not familiar with libcurl, any simple detail could help. Can I have either answer of how curl_easy series works to call multiple callback functions, improper coding of either of the two callback functions, or some missing rules from libcurl?
Feel free to answer me anything.



Things I've tried:



1.I've tried re-compiling versions of libcurl. Now I'm using libcurl-7.64 compiled with "WITH_SSL=static".



2.I've tried many sites, finding the clue: the sites for very small(like 80kb) file will be downloaded completely with the progress bar. But larger file(like 30Mb) will be incomplete. One of my guess is it stopped from some transfer problem since the file is larger.



codes:



static FILE * fp;

static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)



size_t nWrite = fwrite(ptr, size, nmemb, fp);

return nWrite;



static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)



(void)ultotal;
(void)ulnow;
int totaldotz = 40;

double fractiondownloaded = (double)dlnow / (double)dltotal;
int dotz = (int)(fractiondownloaded * totaldotz);

printf("%3.0f%% [", fractiondownloaded * 100); //print the number percentage of the progress

int i = 0;
for (; i < dotz; i++) //print "=" to show progress
printf("=");


for (; i < totaldotz; i++) //print space to occupy the rest
printf(" ");

printf("]r");
fflush(stdout);

return 0;


int download_function(CURL *curl,const char * url, const char * path)



curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
fopen_s(&fp, path, "ab+");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);
char * error = NULL;
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
CURLcode retcCode = curl_easy_perform(curl);
fclose(fp);
const char* pError = curl_easy_strerror(retcCode);
if (curl)
curl_easy_cleanup(curl);

return 0;








c++ c winapi libcurl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 6:58







S.Woung

















asked Mar 27 at 4:59









S.WoungS.Woung

32 bronze badges




32 bronze badges





closed as off-topic by Basile Starynkevitch, Jodocus, Kamiccolo, Umair, Rekshino Mar 27 at 15:07


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – Basile Starynkevitch, Jodocus, Kamiccolo, Umair, Rekshino
If this question can be reworded to fit the rules in the help center, please edit the question.









closed as off-topic by Basile Starynkevitch, Jodocus, Kamiccolo, Umair, Rekshino Mar 27 at 15:07


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – Basile Starynkevitch, Jodocus, Kamiccolo, Umair, Rekshino
If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Basile Starynkevitch, Jodocus, Kamiccolo, Umair, Rekshino Mar 27 at 15:07


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – Basile Starynkevitch, Jodocus, Kamiccolo, Umair, Rekshino
If this question can be reworded to fit the rules in the help center, please edit the question.












  • Welcome to SO. Your question should provide an minimal reproducible example. Without one, it is incomplete, and will eventually get closed. Please edit your question to improve it

    – Basile Starynkevitch
    Mar 27 at 5:28












  • Read also How to debug small programs and read much more about the HTTP protocol. You may want to recompile libcurl with debugging options (e.g. with gcc -g)

    – Basile Starynkevitch
    Mar 27 at 5:30







  • 1





    please print pError to look what is the reason, it is your set timeout 3s expired? curl_easy_setopt(curl,CURLOPT_TIMEOUT,3L); Is it normal after removal?

    – ccxxshow
    Mar 27 at 6:49


















  • Welcome to SO. Your question should provide an minimal reproducible example. Without one, it is incomplete, and will eventually get closed. Please edit your question to improve it

    – Basile Starynkevitch
    Mar 27 at 5:28












  • Read also How to debug small programs and read much more about the HTTP protocol. You may want to recompile libcurl with debugging options (e.g. with gcc -g)

    – Basile Starynkevitch
    Mar 27 at 5:30







  • 1





    please print pError to look what is the reason, it is your set timeout 3s expired? curl_easy_setopt(curl,CURLOPT_TIMEOUT,3L); Is it normal after removal?

    – ccxxshow
    Mar 27 at 6:49

















Welcome to SO. Your question should provide an minimal reproducible example. Without one, it is incomplete, and will eventually get closed. Please edit your question to improve it

– Basile Starynkevitch
Mar 27 at 5:28






Welcome to SO. Your question should provide an minimal reproducible example. Without one, it is incomplete, and will eventually get closed. Please edit your question to improve it

– Basile Starynkevitch
Mar 27 at 5:28














Read also How to debug small programs and read much more about the HTTP protocol. You may want to recompile libcurl with debugging options (e.g. with gcc -g)

– Basile Starynkevitch
Mar 27 at 5:30






Read also How to debug small programs and read much more about the HTTP protocol. You may want to recompile libcurl with debugging options (e.g. with gcc -g)

– Basile Starynkevitch
Mar 27 at 5:30





1




1





please print pError to look what is the reason, it is your set timeout 3s expired? curl_easy_setopt(curl,CURLOPT_TIMEOUT,3L); Is it normal after removal?

– ccxxshow
Mar 27 at 6:49






please print pError to look what is the reason, it is your set timeout 3s expired? curl_easy_setopt(curl,CURLOPT_TIMEOUT,3L); Is it normal after removal?

– ccxxshow
Mar 27 at 6:49













1 Answer
1






active

oldest

votes


















1














@ccxxshow seems right. Set the timeout option gives me CURLE_OPERATION_TIMEDOUT error.



After remove this line I can download about 9MB PDF file successfully.



curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);


enter image description here



enter image description here



My complete code:



#include <curl/curl.h>

static FILE * fp;

static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)



size_t nWrite = fwrite(ptr, size, nmemb, fp);

return nWrite;



static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)



(void)ultotal;
(void)ulnow;
int totaldotz = 40;

double fractiondownloaded = (double)dlnow / (double)dltotal;
int dotz = (int)(fractiondownloaded * totaldotz);

printf("%3.0f%% [", fractiondownloaded * 100); //print the number percentage of the progress

int i = 0;
for (; i < dotz; i++) //print "=" to show progress
printf("=");


for (; i < totaldotz; i++) //print space to occupy the rest
printf(" ");

printf("]r");
fflush(stdout);

return 0;


int download_function(CURL *curl, const char * url, const char * path)


curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
fopen_s(&fp, path, "ab+");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3L);
//curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);
char * error = NULL;
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
CURLcode retcCode = curl_easy_perform(curl);
fclose(fp);
const char* pError = curl_easy_strerror(retcCode);
if (curl)
curl_easy_cleanup(curl);

return 0;



int main()

CURL *testCurl = NULL;
const char *fileAddr = "https://gotocon.com/dl/goto-cph-2015/slides/AndersLybecker_and_SebastianBrandes_DevelopingIoTSolutionsWithWindows10AndAzure.pdf";
download_function(testCurl, fileAddr, "my-9MB.pdf");






share|improve this answer

























  • Thanks Rita Han and @ccxxshowand for answering, I detected too the timeout "3s" is set too soon to download a normal-large size file. And that's the main problem to prevent the program from working well.

    – S.Woung
    Mar 28 at 6:22












  • @S.Woung If the answer help you solved the issue you can accept it. It will help more people searching on this topic.

    – Rita Han - MSFT
    Mar 28 at 6:50











  • Sure. Sweet guide.

    – S.Woung
    Mar 28 at 6:55















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














@ccxxshow seems right. Set the timeout option gives me CURLE_OPERATION_TIMEDOUT error.



After remove this line I can download about 9MB PDF file successfully.



curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);


enter image description here



enter image description here



My complete code:



#include <curl/curl.h>

static FILE * fp;

static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)



size_t nWrite = fwrite(ptr, size, nmemb, fp);

return nWrite;



static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)



(void)ultotal;
(void)ulnow;
int totaldotz = 40;

double fractiondownloaded = (double)dlnow / (double)dltotal;
int dotz = (int)(fractiondownloaded * totaldotz);

printf("%3.0f%% [", fractiondownloaded * 100); //print the number percentage of the progress

int i = 0;
for (; i < dotz; i++) //print "=" to show progress
printf("=");


for (; i < totaldotz; i++) //print space to occupy the rest
printf(" ");

printf("]r");
fflush(stdout);

return 0;


int download_function(CURL *curl, const char * url, const char * path)


curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
fopen_s(&fp, path, "ab+");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3L);
//curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);
char * error = NULL;
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
CURLcode retcCode = curl_easy_perform(curl);
fclose(fp);
const char* pError = curl_easy_strerror(retcCode);
if (curl)
curl_easy_cleanup(curl);

return 0;



int main()

CURL *testCurl = NULL;
const char *fileAddr = "https://gotocon.com/dl/goto-cph-2015/slides/AndersLybecker_and_SebastianBrandes_DevelopingIoTSolutionsWithWindows10AndAzure.pdf";
download_function(testCurl, fileAddr, "my-9MB.pdf");






share|improve this answer

























  • Thanks Rita Han and @ccxxshowand for answering, I detected too the timeout "3s" is set too soon to download a normal-large size file. And that's the main problem to prevent the program from working well.

    – S.Woung
    Mar 28 at 6:22












  • @S.Woung If the answer help you solved the issue you can accept it. It will help more people searching on this topic.

    – Rita Han - MSFT
    Mar 28 at 6:50











  • Sure. Sweet guide.

    – S.Woung
    Mar 28 at 6:55
















1














@ccxxshow seems right. Set the timeout option gives me CURLE_OPERATION_TIMEDOUT error.



After remove this line I can download about 9MB PDF file successfully.



curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);


enter image description here



enter image description here



My complete code:



#include <curl/curl.h>

static FILE * fp;

static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)



size_t nWrite = fwrite(ptr, size, nmemb, fp);

return nWrite;



static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)



(void)ultotal;
(void)ulnow;
int totaldotz = 40;

double fractiondownloaded = (double)dlnow / (double)dltotal;
int dotz = (int)(fractiondownloaded * totaldotz);

printf("%3.0f%% [", fractiondownloaded * 100); //print the number percentage of the progress

int i = 0;
for (; i < dotz; i++) //print "=" to show progress
printf("=");


for (; i < totaldotz; i++) //print space to occupy the rest
printf(" ");

printf("]r");
fflush(stdout);

return 0;


int download_function(CURL *curl, const char * url, const char * path)


curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
fopen_s(&fp, path, "ab+");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3L);
//curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);
char * error = NULL;
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
CURLcode retcCode = curl_easy_perform(curl);
fclose(fp);
const char* pError = curl_easy_strerror(retcCode);
if (curl)
curl_easy_cleanup(curl);

return 0;



int main()

CURL *testCurl = NULL;
const char *fileAddr = "https://gotocon.com/dl/goto-cph-2015/slides/AndersLybecker_and_SebastianBrandes_DevelopingIoTSolutionsWithWindows10AndAzure.pdf";
download_function(testCurl, fileAddr, "my-9MB.pdf");






share|improve this answer

























  • Thanks Rita Han and @ccxxshowand for answering, I detected too the timeout "3s" is set too soon to download a normal-large size file. And that's the main problem to prevent the program from working well.

    – S.Woung
    Mar 28 at 6:22












  • @S.Woung If the answer help you solved the issue you can accept it. It will help more people searching on this topic.

    – Rita Han - MSFT
    Mar 28 at 6:50











  • Sure. Sweet guide.

    – S.Woung
    Mar 28 at 6:55














1












1








1







@ccxxshow seems right. Set the timeout option gives me CURLE_OPERATION_TIMEDOUT error.



After remove this line I can download about 9MB PDF file successfully.



curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);


enter image description here



enter image description here



My complete code:



#include <curl/curl.h>

static FILE * fp;

static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)



size_t nWrite = fwrite(ptr, size, nmemb, fp);

return nWrite;



static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)



(void)ultotal;
(void)ulnow;
int totaldotz = 40;

double fractiondownloaded = (double)dlnow / (double)dltotal;
int dotz = (int)(fractiondownloaded * totaldotz);

printf("%3.0f%% [", fractiondownloaded * 100); //print the number percentage of the progress

int i = 0;
for (; i < dotz; i++) //print "=" to show progress
printf("=");


for (; i < totaldotz; i++) //print space to occupy the rest
printf(" ");

printf("]r");
fflush(stdout);

return 0;


int download_function(CURL *curl, const char * url, const char * path)


curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
fopen_s(&fp, path, "ab+");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3L);
//curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);
char * error = NULL;
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
CURLcode retcCode = curl_easy_perform(curl);
fclose(fp);
const char* pError = curl_easy_strerror(retcCode);
if (curl)
curl_easy_cleanup(curl);

return 0;



int main()

CURL *testCurl = NULL;
const char *fileAddr = "https://gotocon.com/dl/goto-cph-2015/slides/AndersLybecker_and_SebastianBrandes_DevelopingIoTSolutionsWithWindows10AndAzure.pdf";
download_function(testCurl, fileAddr, "my-9MB.pdf");






share|improve this answer













@ccxxshow seems right. Set the timeout option gives me CURLE_OPERATION_TIMEDOUT error.



After remove this line I can download about 9MB PDF file successfully.



curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);


enter image description here



enter image description here



My complete code:



#include <curl/curl.h>

static FILE * fp;

static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)



size_t nWrite = fwrite(ptr, size, nmemb, fp);

return nWrite;



static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)



(void)ultotal;
(void)ulnow;
int totaldotz = 40;

double fractiondownloaded = (double)dlnow / (double)dltotal;
int dotz = (int)(fractiondownloaded * totaldotz);

printf("%3.0f%% [", fractiondownloaded * 100); //print the number percentage of the progress

int i = 0;
for (; i < dotz; i++) //print "=" to show progress
printf("=");


for (; i < totaldotz; i++) //print space to occupy the rest
printf(" ");

printf("]r");
fflush(stdout);

return 0;


int download_function(CURL *curl, const char * url, const char * path)


curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
fopen_s(&fp, path, "ab+");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3L);
//curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L);
char * error = NULL;
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
CURLcode retcCode = curl_easy_perform(curl);
fclose(fp);
const char* pError = curl_easy_strerror(retcCode);
if (curl)
curl_easy_cleanup(curl);

return 0;



int main()

CURL *testCurl = NULL;
const char *fileAddr = "https://gotocon.com/dl/goto-cph-2015/slides/AndersLybecker_and_SebastianBrandes_DevelopingIoTSolutionsWithWindows10AndAzure.pdf";
download_function(testCurl, fileAddr, "my-9MB.pdf");







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 8:37









Rita Han - MSFTRita Han - MSFT

5,8221 gold badge4 silver badges14 bronze badges




5,8221 gold badge4 silver badges14 bronze badges















  • Thanks Rita Han and @ccxxshowand for answering, I detected too the timeout "3s" is set too soon to download a normal-large size file. And that's the main problem to prevent the program from working well.

    – S.Woung
    Mar 28 at 6:22












  • @S.Woung If the answer help you solved the issue you can accept it. It will help more people searching on this topic.

    – Rita Han - MSFT
    Mar 28 at 6:50











  • Sure. Sweet guide.

    – S.Woung
    Mar 28 at 6:55


















  • Thanks Rita Han and @ccxxshowand for answering, I detected too the timeout "3s" is set too soon to download a normal-large size file. And that's the main problem to prevent the program from working well.

    – S.Woung
    Mar 28 at 6:22












  • @S.Woung If the answer help you solved the issue you can accept it. It will help more people searching on this topic.

    – Rita Han - MSFT
    Mar 28 at 6:50











  • Sure. Sweet guide.

    – S.Woung
    Mar 28 at 6:55

















Thanks Rita Han and @ccxxshowand for answering, I detected too the timeout "3s" is set too soon to download a normal-large size file. And that's the main problem to prevent the program from working well.

– S.Woung
Mar 28 at 6:22






Thanks Rita Han and @ccxxshowand for answering, I detected too the timeout "3s" is set too soon to download a normal-large size file. And that's the main problem to prevent the program from working well.

– S.Woung
Mar 28 at 6:22














@S.Woung If the answer help you solved the issue you can accept it. It will help more people searching on this topic.

– Rita Han - MSFT
Mar 28 at 6:50





@S.Woung If the answer help you solved the issue you can accept it. It will help more people searching on this topic.

– Rita Han - MSFT
Mar 28 at 6:50













Sure. Sweet guide.

– S.Woung
Mar 28 at 6:55






Sure. Sweet guide.

– S.Woung
Mar 28 at 6:55







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.





Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript