How to download a file using cURL?

To download a file using cURL you simply need to make a GET request (default behavior) and to specify the -o (output) command line option so that the response is written to a file. Here is a sample command that downloads a file from our hosted version of HTTPBin:

curl https://httpbin.scrapingbee.com/images/png \
 -o image.png

Here we ask for cURL to fetch a png image and write the result inside a file named image.png.

Now, if we remove the -L option, cURL no longer follow redirection the response will be:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   233  100   233    0     0    538      0 --:--:-- --:--:-- --:--:--   546
$ ls
image.png

If you don't use the -o option, the response will be printed to the standard output. And for an image it is not really readable:

What is cURL?

cURL is an open-source command-line tool used to transfer data to and from a server. It is extremely versatile and supports various protocols including HTTP, FTP, SMTP, and many others. It is generally used to test and interact with APIs, download files, and perform various other tasks involving network communication.

Related curl web scraping questions: