# curl Download File: -O, -o, -L and Resume

> Download a file with curl: -O keeps the remote name, -o sets one, -L follows redirects. Plus folders, failing on 404, resume, several files and proxies, tested.

[Home](https://quanticdata.io/) / [Blog](https://quanticdata.io/blog/) / curl Download File: -O, -o, -L and Resume

# How to download a file with curl: -O, -o, redirects, folders and resume

Proxies · Nov 20, 2026 · 5 min read · By [Aldo Morese](https://quanticdata.io/about/), founder of QuanticData

![Downloading a file with curl: -O keeps the remote file name, -o logo.png sets a name, -L follows the 302 from GitHub to the real file, and -C - resumes a partial download; the card shows the real checks: without -L the GitHub link saved 0 bytes, with -L 1461 bytes, and the resumed file was identical to a full download.](https://quanticdata.io/blog/curl-download-file/hero.webp?v=20261120h)

On this page

- [The options at a glance](https://quanticdata.io/blog/curl-download-file/#the-options-at-a-glance)
- [-O and -o: which name the file gets](https://quanticdata.io/blog/curl-download-file/#o-and-o-which-name-the-file-gets)
- [-L: follow redirects, or get an empty file](https://quanticdata.io/blog/curl-download-file/#l-follow-redirects-or-get-an-empty-file)
- [Into a folder, with the server's file name](https://quanticdata.io/blog/curl-download-file/#into-a-folder-with-the-server-s-file-name)
- [Errors: do not save an error page as your file](https://quanticdata.io/blog/curl-download-file/#errors-do-not-save-an-error-page-as-your-file)
- [Resume an interrupted download](https://quanticdata.io/blog/curl-download-file/#resume-an-interrupted-download)
- [Several files, globbing and a progress bar](https://quanticdata.io/blog/curl-download-file/#several-files-globbing-and-a-progress-bar)
- [Downloads that need a login, a timeout or a proxy](https://quanticdata.io/blog/curl-download-file/#downloads-that-need-a-login-a-timeout-or-a-proxy)
- [On Windows](https://quanticdata.io/blog/curl-download-file/#on-windows)

To download a file with curl, use `curl -O URL` to save it under the name in the URL, or `curl -o myname.ext URL` to choose the name. Add `-L` so curl follows redirects; without it, many download links save an empty file. Without `-O` or `-o`, curl prints the file to the terminal.

**Run it on the free credit.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-lead&utm_content=curl-download-file) · [Explore Residential Proxies from $0.80/GB](https://quanticdata.io/residential-proxies/)

We ran each command below on 20 November 2026 with curl 8.22.0 on Windows 11, then checked the files on disk. Sizes and messages are from those runs.

## The options at a glance

| Goal | Command | Our result |
| --- | --- | --- |
| Keep the remote name | `curl -O https://httpbin.org/image/png` | File `png`, 8090 bytes |
| Choose the name | `curl -o logo.png https://httpbin.org/image/png` | `logo.png`, PNG image data, 100 x 100 |
| Follow redirects | `curl -L -o readme.txt URL` | 200, 1461 bytes after 1 redirect |
| Save into a folder | `curl --create-dirs --output-dir files/img -O URL` | `files/img/jpeg`, 35588 bytes |
| Use the server's file name | `curl -J -O URL` | `report.json` from Content-Disposition |
| Fail on 404, keep no file | `curl -f --remove-on-error -o f URL` | exit 22, no file left |
| Resume | `curl -C - -o f URL` | 206, 3000 more bytes, identical file |
| Limit the speed | `curl --limit-rate 50K -o f URL` | 200000 bytes in 4.04 s |

## -O and -o: which name the file gets

`-O` (capital O) takes the last part of the URL as the file name. For `https://httpbin.org/image/png` that is `png`, with no extension, which is why `-o` is often the better choice:

```bash
$ curl -sS -o logo.png https://httpbin.org/image/png
$ file logo.png
logo.png: PNG image data, 100 x 100, 8-bit/color RGB, non-interlaced
$ sha256sum png logo.png
541a1ef5373be3dc49fc542fd9a65177b664aec01c8d8608f99e6ec95577d8c1 *png
541a1ef5373be3dc49fc542fd9a65177b664aec01c8d8608f99e6ec95577d8c1 *logo.png
```

Same bytes, two names. The checksum line is also how to verify a download against a published hash. Without `-O` or `-o`, curl writes the file to your terminal; with a binary file that fills the screen with noise.

## -L: follow redirects, or get an empty file

Download links often answer with a redirect to the real file. GitHub's "raw" links do: the first request returns 302 and an empty body. Without `-L`, curl saves that empty body and stops:

```bash
$ curl -sS -o readme-noL.txt -w "%{http_code} size=%{size_download}\n" https://github.com/curl/curl/raw/master/README
302 size=0
$ curl -sS -L -o readme.txt -w "%{http_code} size=%{size_download} redirects=%{num_redirects}\n" https://github.com/curl/curl/raw/master/README
200 size=1461 redirects=1
```

If a download gives you a 0-byte file, or a small HTML file instead of the archive, this is the first thing to check. `-w "%{http_code}"` shows the status in scripts.

## Into a folder, with the server's file name

- **`--output-dir files/img`** puts the file in that folder; **`--create-dirs`** creates it if it does not exist. Our run created `files/img/jpeg`, 35588 bytes.
- **`-o path/name.ext`** also takes a path into an existing folder: `-o sub/logo2.png` saved the 8090-byte image there.
- **`-J -O`** uses the name in the server's `Content-Disposition` header instead of the URL. Our URL ended in `response-headers?...`, and the file was saved as `report.json`, the name the server sent.

**Try it on your own targets.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-inline&utm_content=curl-download-file) · [Explore Residential Proxies from $0.80/GB](https://quanticdata.io/residential-proxies/)

## Errors: do not save an error page as your file

curl saves whatever the server sends, error or not, and exits 0. A 404 with `-o missing.html` printed `404`, exit 0, and left `missing.html` on disk (empty here; on most sites, an HTML error page). Add `-f` to fail on HTTP errors, and `--remove-on-error` so no partial or error file is left behind:

```bash
$ curl -sS -f --remove-on-error -o missing2.html https://httpbin.org/status/404; echo "exit=$?"
curl: (22) The requested URL returned error: 404
exit=22
$ ls missing2.html
ls: cannot access 'missing2.html': No such file or directory
```

## Resume an interrupted download

`-C -` tells curl to look at the file already on disk and ask the server for the rest. We saved the first 2000 bytes of a 5000-byte file, then resumed:

```bash
$ curl -sS -r 0-1999 -o r.bin https://httpbin.org/range/5000      # r.bin: 2000 bytes
$ curl -sS -C - -o r.bin -w "%{http_code} got=%{size_download}\n" https://httpbin.org/range/5000
206 got=3000
$ curl -sS -o full.bin https://httpbin.org/range/5000
$ cmp r.bin full.bin && echo identical
identical
```

206 means the server sent only the missing part. Resume needs a server that supports ranges: another server we tried ignored the range request and answered 200 instead of 206, so check the status before trusting a resumed file.

## Several files, globbing and a progress bar

```bash
curl -O https://httpbin.org/image/webp -O https://httpbin.org/image/svg     # webp 10568 bytes, svg 8984 bytes
curl "https://httpbin.org/bytes/[1-3]00" -o "bytes_#1.bin"                  # bytes_1.bin 100, bytes_2.bin 200, bytes_3.bin 300
```

One `-O` per URL. `[1-3]` in the URL makes curl fetch each number in turn, and `#1` in the output name is replaced by the current value. `-#` swaps the progress table for a simple bar (`###...### 100.0%`), and `--limit-rate 50K` held a 200000-byte file to 49532 bytes per second.

## Downloads that need a login, a timeout or a proxy

- **Username and password:** `curl -u user:pass -o file URL`; our test file arrived with `"authenticated": true`. See [curl basic auth](https://quanticdata.io/blog/curl-basic-auth/).
- **Timeouts:** on big files, prefer `--speed-limit` and `--speed-time` to a short `--max-time`; see [curl timeouts](https://quanticdata.io/blog/curl-timeout/).
- **Through a proxy:** add `-x` and `-U`. We downloaded the same 1,000,000-byte file through three QuanticData networks:

```bash
curl -x http://residentialboson.quanticdata.io:10000 -U "USER-type-residential-country-us-session-ca01-lifetime-30:PASS" -o rb.bin "https://speed.cloudflare.com/__down?bytes=1000000"
curl -x http://residentialpremium.quanticdata.io:8080 -U "USER-country-de-sid-ca02-ttl-30m:PASS" -o rp.bin "https://speed.cloudflare.com/__down?bytes=1000000"
curl -x http://mobile.quanticdata.io:8080 -U "USER-country-us-type-mobile-sid-ca03-ttl-30m:PASS" -o mb.bin "https://speed.cloudflare.com/__down?bytes=1000000"
```

| Network | Status | Bytes saved |
| --- | --- | --- |
| Residential Basic, US | 200 | 1000000 |
| Residential Premium, Germany | 200 | 1000000 |
| Mobile, US | 200 | 1000000 |

Use the proxy for files that are served differently by country. [how to use a proxy with curl](https://quanticdata.io/blog/how-to-use-a-proxy-with-curl/) covers gateways and SOCKS5, and [wget with a proxy](https://quanticdata.io/blog/wget-proxy-setup/) does the same for wget.

## On Windows

Windows 11 ships the real curl as `curl.exe`; every command here ran with it. In Windows PowerShell, type `curl.exe`, not `curl`, which is an alias of Invoke-WebRequest there. `/dev/null` in our examples works in Git Bash; in PowerShell, `curl.exe -o NUL -w "%{http_code}" URL` discarded the body and printed `200`.

Our [residential proxies](https://quanticdata.io/residential-proxies/) and [mobile proxies](https://quanticdata.io/mobile-proxies/) take the `-x` and `-U` options shown above; there is a [Residential Basic free trial](https://quanticdata.io/residential-proxy-free-trial/).

### Sources & further reading

- [curl manual: -O, --remote-name](https://curl.se/docs/manpage.html#-O)
- [curl manual: -L, --location](https://curl.se/docs/manpage.html#-L)
- [curl manual: -C, --continue-at](https://curl.se/docs/manpage.html#-C)
- [curl manual: --output-dir](https://curl.se/docs/manpage.html#--output-dir)

## FAQ

Quick answers on curl download file.

[Something else? Ask us](mailto:hello@quanticdata.io)

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

`curl -L -O URL` saves it under the name in the URL; `curl -L -o name.ext URL` saves it under your name. `-L` follows redirects, which many download links use.

### Why does curl download an empty file?

The link redirects and curl did not follow it. Our GitHub raw link answered 302 with 0 bytes without `-L`, and 200 with 1461 bytes with `-L`.

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

Use `--output-dir folder -O URL`, plus `--create-dirs` if the folder may not exist, or give a path to `-o`: `-o folder/name.ext`.

### How do I resume a download with curl?

Run the same command with `-C -`. curl checks the size of the file on disk and asks for the rest; in our test the server answered 206 and the resumed file was identical to a full download. The server must support range requests.

### How do I stop curl saving error pages?

Add `-f` so curl fails on HTTP errors (exit 22) and `--remove-on-error` so the file is deleted when that happens. Without them, a 404 is saved under your file name and curl exits 0.

### How do I download several files with curl?

Give one `-O` per URL, or use globbing: `curl "https://host/file[1-3].bin" -o "file_#1.bin"` fetches each number and names each file after it.

## Download from the country you need

Residential and mobile proxies with country targeting for curl -x, for the files that are served differently by location.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-end&utm_content=curl-download-file) · [Explore Residential Proxies from $0.80/GB](https://quanticdata.io/residential-proxies/)

## Related reading

- [curl Timeout: --max-time, --connect-timeout](https://quanticdata.io/blog/curl-timeout/): Proxies · Use --max-time (-m) to cap the whole request and --connect-timeout to cap the connection. Below: the exact "curl: (28)" lines we triggered, what curl did with no timeout at all (21 seconds on Windows), retries, stall detection with --speed-limit, and how both timeouts behave through a proxy.
- [curl Basic Auth: -u, Header, .netrc, Proxy](https://quanticdata.io/blog/curl-basic-auth/): Proxies · curl -u user:password sends HTTP basic authentication: curl base64-encodes the pair into an Authorization header. Below: the header we captured with -v, the same header built by hand, passwords with colons and @, the prompt, .netrc, digest, and why a proxy login goes in -U, not -u.
- [curl Show Response Headers and Send Headers](https://quanticdata.io/blog/curl-headers/): Proxies · curl -i prints the response headers with the body, -I only the headers (with a HEAD request), and -D - -o /dev/null the headers of a normal GET. To send headers, use -H "Name: value", once per header. Below: all of it run for real, plus a single header with -w, removing curl's defaults, headers from a file, and what a proxy sees.

---

Source: https://quanticdata.io/blog/curl-download-file/ · Site index for AI: https://quanticdata.io/llms.txt
