C language batch download files (including source code)

Source: Internet
Author: User

I tried to download some files in batches some time ago, but I found that no one has ever written this on the Internet. Although Thunder can set batch download rules, it is relatively simple, you can only generate up to 999 tasks. Finally, I found an article on CSDN that used C language and thunder to implement batch resource download. So I modified the source code and solved my problem.
My goal is to download thousands of files in batches. The file addresses are from http: // URL/0001.zip to http: // URL/9999.zip. so I learned from the ideas in this article, write one by yourself. In fact, my problem is simpler than that of the author, because he needs to set three variables, and I only need one. The main method is to use the C language to batch write strings to the file, and then open the string and then use the bulk download function of thunder.
The source code I wrote is as follows:
/*
* Powered by 90blog.org
*/
# Include <stdio. h>
 
Void trans (char * c, int I)
{
If (I> = 0 & I <10)
{
Sprintf (c, "000% d", I );
}
Else if (I <100)
{
Sprintf (c, "00% d", I );
}
Else if (I <1000)
{
Sprintf (c, "0% d", I );
}
Else
{
Sprintf (c, "% d", I );
}
}
 
Int main (int argc, char * argv [])
{
Char buff [100];
Char c [5] = "0001 ";
FILE * fp;
Int I = 1;
Int Max = 9999;
Fp = fopen ("download.htm", "w ");
Fputs ("For (I = 1; I <= Max; I ++)
{
Trans (c, I );
Sprintf (buff, "<p> <a href = \" http: // URL/%s.zip/\ "> % s </a> </p> \ n ", c, c );
Fputs (buff, fp );
Puts (buff );
}
Fputs ("Puts ("write OK ");
Fclose (fp );
Return 0;
}
After running, an HTML file is generated directly. After opening the file, you can right-click and download all the links with thunder. A few thousands of tasks are directly added, but thunder is not stuck, and QQ tornado has no response. From this point of view, Thunder is more powerful than QQ tornado in this aspect.
This method can be used to directly download resources in batches, but it seems that in Linux, you can directly use commands to write the addresses to files in batches and then download them in batches. However, I won't, so this method is the only option.

From post-90 blogs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.