How to download files using curl

in #curl5 years ago

curl_logo.png


curl is a tool to transfer data from or to a server, using one of the supported protocols: HTTP, HTTPS, FTP, FTPS, SMB... (see the curl Manual for a list of supported protocols). curl also supports HTTP POST, authentication, cookies, metalinks, file downloading and more. curl is an excelent download manager because support progress bar and allows to pause/resume the download from the last downloaded byte.

Download a single file

$ curl -# -C - -O http://dl-cdn.alpinelinux.org/alpine/v3.8/releases/x86_64/alpine-standard-3.8.0-x86_64.iso

Download the Alpine ISO to the current DIR.

Options
-#: Progress bar.
-C -: Restart the download from last downloaded byte.
-O: Save the file to the current DIR with the same remote name: alpine-standard-3.8.0-x86_64.

Download several files

Using xargs and curl (wget -I style)

$ xargs -a urls.txt -I{} curl -# -O {}

xargs reads line by line the file urls.txt and passes each line to curl, note the xargs option: -I{} and curl option: -O {}, url.txt looks like this:

https://download.libsodium.org/libsodium/releases/latest.tar.gz https://download.libsodium.org/libsodium/releases/libsodium-1.0.16.tar.gz.sig

Using the -K option

$ curl -# -K urls.txt

urls.txt looks like:

url = "url1" output = "nom-fich1" url = "url2" output = "nom-fich2" using -K option, standard input and HEREDOC curl -# -K - <<URL url = "https://download.libsodium.org/libsodium/releases/libsodium-1.0.16.tar.gz" output = "libsodium-1.0.16.tar.gz" output="libsodium-1.0.16.tar.gz.sig" URL url = "https://download.libsodium.org/libsodium/releases/libsodium-1.0.16.tar.gz.sig" Via LibreByte

Sort:  

Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
https://www.librebyte.net/en/internet-browsers/as-download-files-using-curl/

Good tutorial