Download a file with curl: -o, -O, redirects and resume
Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →
Without flags curl prints the download to the console, so files need -o or -O. You almost always need -L too: download links often redirect. Below are commands for a normal download, resume, and checking you got the file and not an HTML error page.
-o or -O
-o name saves under the given name. -O takes the name from the last part of the URL. If the URL ends in download or has parameters the name will be odd: use -o, or -J with -O to take the name from Content-Disposition.
Do not save an error page
If the link expired, the server returns 404 or 403 with an HTML page and curl saves it under the archive name. -f makes curl fail on HTTP 400 and above and not write the error body to the file.

Resume and retries
Resume a broken large download with -C - and the same -o: curl checks the size already saved. On an unstable network add --retry with a count, and in scripts --max-time so the download never hangs forever.
Download commands
# сохранить под своим именем, пройти редиректы, не сохранять страницу ошибки
curl -fL -o report.zip https://files.example.com/download?id=42
# имя из адреса
curl -O https://files.example.com/builds/app-1.4.2.tar.gz
# имя из заголовка Content-Disposition
curl -OJ -L https://files.example.com/download?id=42
# докачать оборванную загрузку
curl -C - -o big.iso https://mirror.example.com/big.iso
# повторы и ограничение времени для скрипта
curl -fL --retry 5 --retry-delay 3 --max-time 600 -o big.iso https://mirror.example.com/big.iso
Check you got the right file
- The size looks right, not a few kilobytes.
- The file command reports an archive or binary, not an HTML document.
- The checksum matches the published one: sha256sum on Linux, certutil -hashfile on Windows.
If a download breaks with an error number, see curl errors.
More on curl
Section overview and all guides: curl command cheat sheet: flags and examples for APIs.
- curl through a proxy: -x, environment variables, SOCKS and no_proxy
- PHP cURL: GET and POST requests with JSON, headers and error handling
- Webhook: what it is, how it works and how to test it
- curl GET request: parameters, response headers and status code
- cURL examples: GET and POST requests with JSON on Linux, Windows and PowerShell
Frequently asked questions
How do I download a file with curl?
curl -L -o name URL; -O uses the URL name, -L follows redirects.
How do I resume?
Run the same command with -C - and the same -o name.
Why did curl save HTML?
The server returned an error or login page; add -f.
Repeat this on your own API
Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.
Download FreeDownload and first runNo sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.
References
Start with the linked example and compare its result with your own test requirement.