How to download a file using cURL?
A file download with cURL needs two things: a request for the resource and a destination for the response.
Because GET is the default method, the key addition is the output option that saves the response body to a file on disk.
Save the response to a named file
Start with the URL of the file you want. cURL will issue a GET request by default, so no method flag is required for a straightforward download. Add the output option and give the local filename you want the response written to. In the worked example, a PNG image is fetched from the HTTPBin test service and saved locally as image.png. The exact command is provided by protected module code0001, which uses the configured HTTPBIN_BASE_URL origin token rather than a hard-coded host.
Why the output option matters for binary files
The output option is the difference between a usable download and a terminal full of binary data. Without it, cURL prints the response to standard output. That is fine for readable text, but for an image the printed bytes are not meaningfully readable and are not saved anywhere. Always pair a binary download with an output filename, then confirm the file exists in the working directory. Protected module code0002 shows the kind of transfer summary and directory listing you can expect after a successful run.
Quick verification checklist
Before running the command, check three things: the URL points to the intended resource, the output filename is one you can find again, and the current directory is where you expect the file to land. After running it, verify the file is present and has a plausible size rather than relying only on the transfer summary. If the content is an image or other binary data, open or inspect the saved file instead of judging it from terminal output.
What is cURL?
cURL is an open-source command-line tool for moving data between a client and a server. It supports many protocols, including HTTP, FTP and SMTP, and is widely used to test and interact with APIs, download files, and perform other network communication tasks. That versatility is why the same tool covers both simple downloads and more involved request work.
| Situation | What cURL does | Practical result |
|---|---|---|
| Output option present | Writes the response body to the named local file | A saved file such as image.png that can be opened or inspected |
| Output option omitted | Prints the response to standard output | Readable for text, but binary content such as an image is not usefully readable |
Based on the supplied example and explanations; redirect behaviour is not demonstrated in the protected example command.
Frequently asked questions
Do I need to specify a request method to download a file with cURL?
cURL uses a GET request by default. Adding the output option directs the response body to a named file instead of printing it to the terminal, which is especially important for binary content such as images.
What happens if I omit the output option?
Without an output option, cURL writes the response to standard output. For an image, that output is binary data rather than readable text, so saving it to a file is the practical choice.
What is cURL used for?
cURL is a command-line tool for transferring data between a client and a server. It supports protocols including HTTP, FTP and SMTP, and is commonly used to test APIs, download files and carry out other network tasks.
curl {{HTTPBIN_BASE_URL}}/images/png \
-o image.png