Download Files In C++ Using LibCurl and Indicators Progress Bars
Introduction
Downloading files and showing the download progress in Python is simple. However, sometimes we would like to do the same thing in a C++ program.
In this blog post, I would like to show how to download files using the LibCurl library and the indicators progress bar library in C++.
Download C++ Application
Download Dependencies
We have to install the following dependencies.
1 | $ sudo apt-get update |
Alternatively, we could also use Docker container created from the following Dockerfile.
1 | FROM ubuntu:20.04 |
To display a progress bar for downloading the file, we could use the indicators header-only library. Just download the header file and compile the download application with the header file.
1 | $ wget https://raw.githubusercontent.com/p-ranav/indicators/v2.2/single_include/indicators/indicators.hpp |
Implement Application
The simple download application was implemented as follows.
1 |
|
Build Application
1 | $ g++ curl_download.cpp indicators.hpp -o curl_download -lcurl |
Run Application
We could use the download application to download a common machine learning dataset.
1 | $ ./curl_download https://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz |
References
Download Files In C++ Using LibCurl and Indicators Progress Bars
https://leimao.github.io/blog/Download-Using-LibCurl/