---
title: "How to Download a File With curl: -O, -o, Resume and Proxy"
description: "To download a file with curl, use -O to keep the remote name or -o to pick one. Add -L for redirects, -f for errors, -C - to resume and -x for a proxy."
url: https://proxynet.io/blog/curl-download-file
date: 2026-11-30
author: "Acar Diveroli"
category: "Tutorial, Integration"
lang: en
---

# How to Download a File With curl: -O, -o, Resume and Proxy

A build script downloads a release archive with `curl -O`, and the next step, `unzip`, stops with "End-of-central-directory signature not found". The file on disk is called `latest` and has 0 bytes, or it is 100 bytes of HTML that starts with `<!DOCTYPE html>` and says "404 Not Found". curl did exactly what it was told: it saved the redirect response, or the error page, under the name in the URL and reported success.

This post covers the options that turn curl into a dependable downloader: `-O` and `-o`, following redirects with `-L`, the server's file name with `-J`, target folders, `--fail` so an error page never becomes your file, resuming with `-C -`, retries, speed limits, several files in one command, checksums, curl on Windows and downloading through a proxy. Every command was run on 28 November 2026 with curl 8.23.0 in Git Bash and with Windows' own `curl.exe` 8.22.0, against a small test server and test proxy on our own machine.

> **Note: Short answer**
>
> `curl -O https://example.com/files/tool.zip` saves the file under its remote name, `tool.zip`, in the current folder; `curl -o mytool.zip URL` saves it under a name you choose. For real downloads add `-L` to follow redirects and `-f` so an HTTP error such as 404 makes curl exit with code 22 instead of saving the error page: `curl -fL -O URL`. Resume a broken download with `-C -`, retry temporary failures with `--retry 3`, save into a folder with `--output-dir dir --create-dirs`, and send the download through a proxy with `-x "http://user:pass@host:port"`. In Windows PowerShell 5.1, type `curl.exe`, because `curl` there is an alias for `Invoke-WebRequest`.

## What does curl do with a file by default?

By default curl writes what it downloads to standard output, the terminal, not to a file. `curl https://example.com/report.csv` prints the CSV on screen; to keep it, you either redirect the output (`> report.csv`) or tell curl to write a file itself with `-O` or `-o`. The second way is better, because curl then knows the file name and can resume, skip or remove the file for you.

curl also does not judge the response. A 200 with your file, a 302 redirect with an empty body and a 404 page are all "data" to it, and without extra options it saves each of them and exits with code 0. The options in this post exist to close those gaps.

## What is the difference between curl -O and -o?

`-O` (capital, long form `--remote-name`) names the local file after the last part of the URL; `-o name` (`--output`) uses the name you give.

| Command | Saved as | Note |
|---|---|---|
| `curl -O URL/files/tool-1.4.2.zip` | `tool-1.4.2.zip` | Remote name |
| `curl -o mytool.zip URL/files/tool-1.4.2.zip` | `mytool.zip` | Your name, may include a path |
| `curl -O "URL/download?id=42"` | `download` | Query string dropped |
| `curl -O URL/releases/` | `releases` | curl 8.10.0 and later |

Both overwrite an existing file of the same name without asking. In our test, running `curl -O` twice left one `report.csv` with the newer content. Two newer options change that: `--no-clobber` (curl 7.83.0) saves the second copy as `report-1.csv`, and `--skip-existing` (curl 8.10.0) does not send the request at all when the file is already there.

For a URL that ends in a slash, older curl versions stop with an error instead of using the directory name. When a URL has no usable name, use `-o`.

## How do you follow redirects when downloading with curl?

Add `-L` (`--location`). Download links often answer with a 301, 302 or 307 redirect to a mirror, a CDN or a versioned file, and curl does not follow them unless you ask. Without `-L`, `curl -O https://example.com/latest` saved a 0-byte file named `latest` in our test and still exited with 0.

With `-L`, curl repeats the request at the new address. Keep in mind where the name comes from: `curl -L -O .../latest` still saved the file as `latest`, the name in the URL you typed, not the name of the file the redirect pointed to. To see where you ended up, print it:

```bash
curl -L -o tool.zip -w "%{http_code} %{url_effective} %{num_redirects}\n" https://example.com/latest
```

Our test printed `200 http://127.0.0.1:52817/files/tool-1.4.2.zip 1`: status, final URL and one redirect.

## How do you keep the file name the server sends?

Use `-J` (`--remote-header-name`) together with `-O`. Many download endpoints have URLs like `/download?id=42` and send the real name in a `Content-Disposition` header. With `-O` alone our test saved a file called `download`; with `-OJ` it saved `report-2026-11.csv`, the name from the header.

Two details from the [curl manual](https://curl.se/docs/manpage.html) matter here. If the header's file name contains a path, curl strips it, so a server cannot write outside your folder. And `-J` refuses to overwrite an existing file: our second run stopped with `curl: (23) client returned ERROR on write of 64 bytes`. Add `--clobber` when overwriting is what you want.

## How do you download a file to a specific directory with curl?

Use `--output-dir` (curl 7.73.0 and later) for the folder and `--create-dirs` so curl creates it when it is missing:

```bash
curl -fL --create-dirs --output-dir downloads/2026-11 -O https://example.com/files/report.csv
```

Without `--create-dirs`, a missing folder failed with `curl: (23) client returned ERROR on write of 7 bytes`. You can also put the path into `-o` (`-o data/raw/report.csv`); `--create-dirs` works there too. A path with spaces needs quotes.

## How do you stop curl from saving an error page as the file?

Add `-f` (`--fail`). With it, an HTTP status of 400 or higher makes curl exit with code 22 and write nothing. In our test, `curl -O .../missing.zip` saved the 100-byte HTML error page as `missing.zip` with exit code 0; `curl -f -O` printed `curl: (22) The requested URL returned error: 404` and left no file.

The usual combination for scripts is `-fsSL`: `-f` for errors, `-s` to hide the progress meter, `-S` to still show error messages, and `-L` for redirects.

When you want the error body for debugging, `--fail-with-body` (curl 7.76.0) exits with 22 but keeps the body. Add `--remove-on-error` (curl 7.83.0) to delete the output file whenever curl fails. The manual itself warns that `--fail` is "not fail-safe" in every case, so a script should also check the file itself: its size or, better, its checksum.

## How do you resume an interrupted download with curl?

Run the same command again with `-C -` (`--continue-at -`). curl checks how many bytes the local file already has and asks the server for the rest with a `Range` header:

```bash
curl -fL -C - -o tool-1.4.2.zip https://example.com/files/tool-1.4.2.zip
```

On our test machine, a 5,242,880-byte download was cut off with `curl: (18) end of response with 2621440 bytes missing`. The command above then sent `Range: bytes=2621440-`, got `206 Partial Content`, fetched the missing 2,621,440 bytes, and the SHA-256 of the result matched the original. The [everything curl chapter on resuming](https://everything.curl.dev/usingcurl/downloads/resume.html) describes the same mechanism.

A few behaviours are worth knowing:

- **Already complete.** Running `-C -` on a finished file got `416` from the server; curl left the file alone and exited with 0, even with `-f`. That makes `-C -` safe to put in a script that may run twice.
- **No range support.** Against Python's built-in `http.server`, which ignores `Range`, curl stopped with `curl: (33) HTTP server does not seem to support byte ranges. Cannot resume.` and did not touch the partial file. Delete it and download again from the start.
- **Changed file.** curl only appends. If the file on the server changed between attempts, the result is a mix of two versions, which only a checksum reveals.
- **Not with every option.** The manual says `--no-clobber` and `--remove-on-error` cannot be used together with `--continue-at`, and uploads with POST or PUT cannot be resumed.

## How do you retry a failed curl download?

Add `--retry N`. curl then retries what the manual calls transient errors: a timeout and the HTTP codes 408, 429, 500, 502, 503, 504, 522 and 524. It waits one second before the first retry and doubles the wait each time, up to 10 minutes.

```bash
curl -fL --retry 3 --retry-connrefused --connect-timeout 10 -o report.csv https://example.com/report.csv
```

Against our test endpoint that answered 503 twice, curl printed `Warning: Problem : HTTP error. Retrying in 1 second. 3 retries left.`, then the same with two left, and saved the file on the third try. Both waits were the one second our server asked for in its `Retry-After` header, and the 503 was retried with or without `-f`. `--retry-connrefused` adds "connection refused" to the list, `--retry-all-errors` (curl 7.71.0) retries everything, and `--retry-max-time` caps the total time.

Retries are for servers that are briefly unavailable. A 429 means the server wants fewer requests, so the answer is a pause and a lower rate, not a tighter loop; [HTTP 429 Too Many Requests](/blog/http-429-too-many-requests) explains how to read its headers. Note that a connection cut in the middle (exit code 18) is not on the transient list: the script further down handles that case with `-C -`.

## How do you limit the download speed and show a progress bar?

`--limit-rate` caps the transfer speed; `-#` replaces the default progress table with a single bar.

```bash
curl -# --limit-rate 1M -O https://example.com/files/tool-1.4.2.zip
```

The value is in bytes per second, with `K`, `M` and `G` as suffixes. In our run, `--limit-rate 1M` downloaded the 5,242,880-byte test file in 5.0 seconds at an average of 1,048,612 bytes per second, so `1M` means 1,048,576 bytes and the cap holds closely. The manual notes that the limit applies to uploads too. Use it on a shared office line or when the server's terms ask for gentle downloads. For logs, `-s -S` hides the meter but keeps errors.

## How do you download multiple files with curl?

Give each URL its own `-O`, or put `--remote-name-all` before the URLs:

```bash
# one -O per URL
curl -fL -O https://example.com/files/part1.csv -O https://example.com/files/part2.csv

# every URL saved under its remote name
curl -fL --remote-name-all https://example.com/files/part1.csv https://example.com/files/part2.csv
```

A single `-O` covers only one URL. `curl -O A B` saved A and printed B in the terminal in our test.

For numbered files, curl's URL globbing expands one URL into many. `[1-5]` is a range, `[01-03]` keeps the zero padding, and `{1,3}` is a list. In `-o`, `#1` stands for the value of the first pattern:

```bash
curl -fL -O "https://example.com/files/part[1-5].csv"
curl -fL "https://example.com/files/part{1,3}.csv" -o "copy_#1.csv"
```

The first command saved `part1.csv` to `part5.csv`; the second saved `copy_1.csv` and `copy_3.csv`. Quote these URLs so the shell does not expand the brackets first. If a real URL contains `[` or `]`, turn globbing off with `-g`; otherwise curl stops with `curl: (3) bad range`.

`-Z` (`--parallel`, curl 7.66.0) runs the transfers at the same time, 50 at most by default. On someone else's server keep it low with `--parallel-max 3` or leave it out, and download only files you are allowed to fetch: a glob is a shortcut for a known file list, not a way to copy a whole site.

## How do you download a file that needs a username and password?

Use `-u user:pass` (`--user`) for the server's own login, such as HTTP Basic authentication on a private file area. Without it our protected test file returned `curl: (22) The requested URL returned error: 401`; with `-u` it downloaded.

If you give only the user name (`-u user`), curl asks for the password, so it does not land in your shell history. For a token-based API, send the header instead: `-H "Authorization: Bearer $TOKEN"`. Do not confuse `-u` with `-U`: lower case logs in to the server, upper case to a proxy.

## How do you verify a downloaded file with a checksum?

Compare the file's SHA-256 hash with the one the publisher lists. A matching hash means the file arrived complete and unchanged; a truncated download or a mixed resume fails here even when curl reported success.

On Linux and in Git Bash on Windows, `sha256sum -c` reads a checksum file in the usual `hash  filename` format:

```bash
curl -fL -O https://example.com/files/tool-1.4.2.zip -O https://example.com/files/tool-1.4.2.zip.sha256
sha256sum -c tool-1.4.2.zip.sha256
```

It printed `tool-1.4.2.zip: OK`; with a cut copy it printed `tool-1.4.2.zip: FAILED` and exited with 1. On Windows without Git Bash there are two built-in tools:

```powershell
# PowerShell: SHA256 is the default algorithm
Get-FileHash .\tool-1.4.2.zip
(Get-FileHash .\tool-1.4.2.zip).Hash -eq "5e0f0f83fbc2fb78100946068dfc9c3d070955d34384ed57f1f4e6ce30b5f065"

# cmd or PowerShell
certutil -hashfile tool-1.4.2.zip SHA256
```

`Get-FileHash` prints the hash in capital letters, and PowerShell's `-eq` ignores case, so the comparison returned `True` against the lowercase value. Microsoft's [Get-FileHash reference](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash) lists the other algorithms; avoid MD5 and SHA1 for anything that must resist tampering.

## How do you download a file with curl on Windows?

Windows 10 and 11 include curl as `curl.exe`; in cmd you can type `curl`, in Windows PowerShell 5.1 type `curl.exe`. In 5.1, `curl` is an alias for `Invoke-WebRequest`: on our machine `curl -O URL` answered `Cannot process command because of one or more missing mandatory parameters: Uri.` The same line with `curl.exe` saved the file. PowerShell 7 no longer has this alias.

The [curl project's page on the Windows build](https://curl.se/windows/microsoft.html) adds two points. Microsoft builds it separately, so it lags behind curl releases and leaves out some features, among them HTTP/2, HTTP/3, SFTP and SCP. Our `curl.exe` was 8.22.0 while Git Bash came with 8.23.0, and every command in this post worked with both. Check yours with `curl.exe --version`: options added in 8.10.0, such as `--skip-existing`, need at least that version.

Quoting is the other trap. In cmd, a URL with `&` needs double quotes, and in a `.cmd` batch file `%` must be written `%%`. In PowerShell, quote URLs with `[`, `{` or `@`.

## How do you download a file through a proxy with curl?

Add `-x` with the proxy address; every download option above stays the same:

```bash
curl -fL -x "http://user:pass@pr.proxynet.io:8000" -C - -O https://example.com/files/tool-1.4.2.zip
```

Through our local test proxy, `-w "%{proxy_used}"` printed `1` and the proxy logged the request; a resume through the proxy got `206` and a matching checksum. Without credentials the proxy answered `407`, which `-f` turned into exit code 22. If the password contains `@` or `:`, pass it with `--proxy-user "user:pass"` (short `-U`) instead of putting it in the address. Proxy and server logins can be combined: `-U` for the proxy, `-u` for the file area.

For SOCKS5, use `--socks5-hostname` or the equivalent `socks5h://` scheme, so the proxy resolves the host name:

```bash
curl -fL --socks5-hostname pr.proxynet.io:1080 --proxy-user "user:pass" -O https://example.com/files/report.csv
```

Our test SOCKS5 proxy received the host name with `--socks5-hostname` and an IP address that curl had resolved itself with plain `socks5://`. Wrong SOCKS credentials end with `curl: (97) User was rejected by the SOCKS5 server`.

A proxy is useful when the download must come from a particular address or country: checking that your own release mirror serves the right file in another region, or testing how your download page answers visitors from another market. A [Residential Proxy](https://proxynet.io/residential-proxy) takes the country and session in the username, with the same `-x` line.

For tools or networks that only speak SOCKS, a [SOCKS5 Proxy](https://proxynet.io/socks5-proxy) carries the same commands, and an IP whitelist in the panel keeps the password out of your scripts.

Environment variables, `.curlrc` and every proxy error message are covered in [cURL with Proxy](/blog/curl-proxy).

## Example: a download script that resumes, retries and checks the hash

This Bash script (Linux, macOS or Git Bash) downloads one file into `downloads/`, resumes it if the connection breaks, stops on real errors and finally checks the SHA-256 file next to it:

```bash
#!/usr/bin/env bash
# get-file.sh: download a file, resume after a break, retry, then check its SHA-256
# usage: ./get-file.sh URL [SHA256_URL]
set -euo pipefail

URL="${1:?usage: get-file.sh URL [SHA256_URL]}"
SUM_URL="${2:-$URL.sha256}"
DIR="${DIR:-downloads}"
PROXY="${PROXY:-}"   # e.g. http://user:pass@pr.proxynet.io:8000

FILE="$(basename "${URL%%\?*}")"
opts=(--fail --location --silent --show-error
      --retry 3 --retry-connrefused --connect-timeout 10
      --create-dirs --output-dir "$DIR")
if [ -n "$PROXY" ]; then opts+=(--proxy "$PROXY"); fi

for attempt in 1 2 3 4; do
  rc=0
  curl "${opts[@]}" --continue-at - -o "$FILE" "$URL" || rc=$?
  if [ "$rc" -eq 0 ]; then break; fi
  case "$rc" in
    18|28|56) ;;                      # cut off, timed out, connection lost: resume
    *) echo "curl exit code $rc, not retrying" >&2; exit "$rc" ;;
  esac
  if [ "$attempt" -eq 4 ]; then echo "giving up on $URL" >&2; exit "$rc"; fi
  echo "attempt $attempt stopped at $(wc -c < "$DIR/$FILE") bytes, resuming" >&2
  sleep 2
done

curl "${opts[@]}" -o "$FILE.sha256" "$SUM_URL"
cd "$DIR" && sha256sum -c "$FILE.sha256"
```

- `--retry 3` handles busy servers (503, 429 and the like); the loop handles a transfer cut in the middle, which `--retry` does not.
- `--continue-at -` makes every attempt pick up where the last one stopped, and does nothing harmful when the file is already complete.
- Exit code 22 (404, 403) ends the script at once, because downloading the same missing file again will not help.

On our test server, whose first response stopped halfway, the script printed `attempt 1 stopped at 2621440 bytes, resuming` and then `tool-2.0.0.zip: OK`. Run a second time it printed `OK` again without downloading. With `PROXY=...` set it ran through the test proxy, and for a missing file it stopped after one try with `curl exit code 22, not retrying`.

## Where is downloading files with curl used?

Build and deploy scripts fetch release archives, installers and container tools with curl because it is on almost every system and its exit codes are easy to check. Data teams download nightly exports from partner servers or cloud storage links. Administrators fetch updates on servers without a browser, often through a company proxy. QA teams check that a download link answers with the right file, size and hash from different networks.

## Common curl download errors and how to fix them

Exit codes and messages as curl 8.23.0 printed them in our tests:

- **`(3) bad range`** A `[` or `]` in the URL was read as a glob. Add `-g`.
- **`(18) end of response with … bytes missing`** The connection closed early. Resume with `-C -`.
- **`(22) The requested URL returned error: 404`** `-f` caught an HTTP error. Check the URL, the login (401) or the proxy credentials (407).
- **`(23) client returned ERROR on write`** curl could not write the file: the folder is missing (add `--create-dirs`), the disk is full, or `-J` found an existing file (add `--clobber`).
- **`(33) HTTP server does not seem to support byte ranges`** The server cannot resume. Delete the partial file and start again.
- **`(97) User was rejected by the SOCKS5 server`** Wrong SOCKS5 username or password.
- **A 0-byte file and exit code 0** A redirect without `-L`.
- **A small HTML file instead of the archive** An error page saved without `-f`, or a login page.
- **`Cannot process command … missing mandatory parameters: Uri`** `curl` in PowerShell 5.1 reached `Invoke-WebRequest`. Type `curl.exe`.

## Decision guide

| Need | Recommendation |
|---|---|
| Keep the remote file name | `-O` |
| Choose the name or path | `-o name` |
| Link redirects to a mirror | `-L` |
| Name comes from the server | `-OJ` |
| Save into a folder | `--output-dir dir --create-dirs` |
| Never save an error page | `-f`, or `-fsSL` in scripts |
| Resume after a break | `-C -` with the same name |
| Busy server, 503 or 429 | `--retry 3` |
| Many numbered files | `-O "url/part[1-5].csv"` |
| Prove the file is intact | `sha256sum -c` or `Get-FileHash` |
| Windows PowerShell 5.1 | `curl.exe` |
| Download through a proxy | `-x "http://user:pass@host:port"` |

## Frequently asked questions

### How do I download a file from a URL with curl?

Run `curl -fL -O https://example.com/file.zip`. `-O` saves it under its remote name in the current folder, `-L` follows redirects and `-f` stops on HTTP errors instead of saving an error page.

### How do I download a file to a specific directory with curl?

Use `curl -fL --create-dirs --output-dir /path/to/dir -O URL`, or give the full path with `-o /path/to/dir/name.zip`. `--output-dir` needs curl 7.73.0 or later.

### Why does curl download a 0-byte or HTML file instead of the real file?

A 0-byte file usually means a redirect that curl did not follow: add `-L`. A small HTML file is usually an error or login page: add `-f` so curl exits with code 22 instead, and check the URL and credentials.

### How do I resume a curl download?

Repeat the same command with `-C -` and the same output name. curl asks the server for the remaining bytes; if the server does not support ranges, curl stops with exit code 33 and you have to download from the start.

### Should I use curl or wget to download files?

Both download files well. wget is made for downloading and can follow links to fetch a directory tree, while curl handles more protocols and is built into Windows 10 and 11. wget's proxy setup is in [Using a Proxy with wget](/blog/wget-proxy).

### How do I download a file with a username and password in curl?

Use `-u user:pass` for the server's login, or `-u user` to be asked for the password. For a proxy login use `-U user:pass` or `--proxy-user`.

## Summary

For a dependable download, use `curl -fL -O URL`: the remote name, redirects followed and no error pages saved as files. Add `--output-dir` with `--create-dirs` for the folder, `-C -` to resume, `--retry` for busy servers, and finish with a SHA-256 check, because only the hash proves the file is complete. On Windows PowerShell 5.1 type `curl.exe`, and when a download has to leave from a particular address or country, add `-x` and keep everything else unchanged; [Proxynet proxies](/proxy) provide HTTP and SOCKS5 endpoints for exactly that.
