---
title: "How to Use cURL to Download Files: A Step-by-Step Guide"
description: "Learn how to use cURL to download files with step-by-step examples. Master downloading single and multiple files, handling redirects, setting user agents, and more."
url: "https://iproyal.com/blog/curl-download-file/"
---

- [EN - English](https://iproyal.com/)
   
  [中文 - Chinese](https://china-iproyal.com/)

[Book a Demo](https://iproyal.com/request-a-demo/) [Create Account](https://dashboard.iproyal.com/register/) [Create Account](https://dashboard.iproyal.com/register/) [Login](https://dashboard.iproyal.com/login/) [Login](https://dashboard.iproyal.com/login/)

[Book a Demo](https://iproyal.com/request-a-demo/)

[Back to blog](https://iproyal.com/blog/)

# How to Use cURL to Download Files: A Step-by-Step Guide

[Justas Vitaitis](https://iproyal.com/blog/authors/justas-vitaitis/)

[Last updated - October 31, 2024 ‐ 4 min read](https://iproyal.com/blog/authors/justas-vitaitis/)

[Tutorials](https://iproyal.com/blog/category/tutorials/)

## Key Takeaways

- cURL is a powerful command line tool that supports downloading over many protocols, making it ideal for scripting and automation.

- You can use cURL to download multiple files by combining it with shell loops, PowerShell, or by using a configuration file with the *--config&#x20;*&#x6F;ption.

- Customizing request headers, setting a user agent, or using authentication helps you handle protected or complex downloading tasks with ease.

cURL is a command line tool that helps developers interact with servers. It lets you send or get data using different internet protocols, and people often use it to download software, scripts, config files, images, and more from a remote server.

We’ll break down how to download files with cURL and show you how flexible it can be in downloading both single and multiple files.

If you prefer the video format, we’ve got you covered:

## What Is cURL and Why Use It to Download Files?

cURL stands for “Client URL”. It’s a free, open-source command line tool used for sending and receiving data using URL syntax. It supports protocols like HTTP, HTTPS, FTP, and many more. On most Unix-like operating systems like macOS and Linux, it comes pre-installed.

You’ll find cURL useful for:

- Sending [GET ](https://iproyal.com/blog/curl-get-request/)or [POST ](https://iproyal.com/blog/curl-post-request/)requests.
- Automating downloads.
- Testing APIs.
- Uploading or downloading content from servers.

Because of its broad support for protocols and simple usage, many developers prefer cURL to download files instead of using a browser or another app.

## Basic Syntax to Download a File Using cURL

Here’s the most basic way to use cURL to download a file:

```javascript
curl -O https://iproyal.com/robots.txt
```

It saves the remote file with the same name locally. Let’s break down the common flags:

- ***-O&#x20;***(uppercase o). Saves the file with its original name.
- ***-o filename.&#x20;***&#x4C;et you choose a custom filename.
- ***-L.&#x20;***&#x46;ollows redirects if the URL changes.

Redirects happen more often than you would think. Some URLs don’t point straight to the file but instead pass you along. Learn how to [follow redirects using cURL ](https://iproyal.com/blog/curl-follow-redirects/)to avoid errors during your file downloads.

## Downloading Files With cURL - Common Examples

There are several methods you can use to download files with cURL, and here’s a quick overview of the most common ones.

### 1. Basic File Download

```javascript
curl -O https://cms.iproyal.com/uploads/IPR_Web_Preview_2845a84108.jpg
```

Running the command above will download one of IPRoyal’s brand images. Use the command when you want to save a remote file exactly as it is. It’s great for images, patches, or configuration files.

### 2. Download With Custom Filename

```javascript
curl -o custom.jpg https://cms.iproyal.com/uploads/IPR_Web_Preview_2845a84108.jpg
```

With this line, you can name the file whatever you want. It’s useful when you want consistent naming for scripts or batch jobs.

The remainder of cURL commands are situational and are trickier to show perfect examples of, so we’ll be using placeholder URLs.

### 3. Resume an Interrupted Download

```javascript
curl -C - -O https://example.com/largefile.zip
```

It will resume the download where it left off. If your downloading session breaks mid-way, you don’t need to start all over again.

### 4. Download Behind Redirects

```javascript
curl -L -O https://short.url/file
```

Many links, especially from services like Dropbox or Google Drive, use redirects. Without *-L,* cURL won’t follow them, so the download may fail.

### 5. Use With Proxy or Authentication

```javascript
curl -u user:password -O https://example.com/protected.zip
```

Or if you want to [set a user agent ](https://iproyal.com/blog/curl-set-user-agent/)for more control:

```javascript
curl -A "MyAgent/1.0" -O https://example.com/data.json
```

For more secure areas or APIs, using proper [cURL authentication ](https://iproyal.com/blog/curl-basic-auth/)can help you download files more safely.

## Downloading Multiple Files With cURL

You can also download multiple files at once using a few different methods.

### 1. Multiple -O Commands

```javascript
curl -O https://example.com/file1.txt -O https://example.com/file2.txt
```

Quick and easy when you know the exact URLs. Just list them one after the other.

### 2. Loop Through a .txt List

First, create a text file with URLs, one per line:

```javascript
https://example.com/file1.txt
https://example.com/file2.txt
```

Then, on Unix-like systems (Linux, macOS, WSL), run:

```javascript
while read url; do curl -O "$url"; done < urls.txt
```

It tells the shell to read each line from *urls.txt* and pass it to cURL. However, cURL itself cannot directly parse a *.txt* list of URLs. The loop works in bash or similar shells, but not in Windows CMD.

On Windows, you have two options: using PowerShell or writing a simple batch script with each URL in its own line. If you’re using PowerShell:

```javascript
Get-Content urls.txt | ForEach-Object { curl.exe -O $_ }
```

### 3. Batch Script for Windows

Create a *download.bat:*

```javascript
curl -O https://example.com/file1.zip
curl -O https://example.com/file2.zip
```

Run the batch script to download files one by one. Bat files are a simple automation tool that helps keep things tidy when working with bulk files.

## Handling Output and File Saving

Sometimes you may not want to save the downloaded file with its original name. Or you don’t want it to overwrite existing files.

Use *-o* for custom names, like in our previous example, but if you want to send output to stdout instead of saving, there’s also the option of skipping the *-o* or *-O:*

```javascript
curl https://example.com/data.json
```

To avoid overwriting, you can add a check in your script or use different names. Some like to include timestamps in the filename, for example.

You can also use built-in flags like *-i* (include headers) or *-D -* (print headers). For more details, check out our detailed guide on [showing response headers in cURL ](https://iproyal.com/blog/curl-show-response-headers/).

## Conclusion

Using cURL to download files is fast, flexible, and powerful. You can fetch a single file, download multiple files with a script, or resume broken downloads.

If you’d like to compare tools, check out our breakdown of [cURL vs Wget ](https://iproyal.com/blog/curl-vs-wget/)to help you decide which one fits your needs best: a general-purpose transfer tool (cURL) or a file-centric downloader (Wget).

[Create Account](https://dashboard.iproyal.com/)

[Author](https://iproyal.com/blog/authors/justas-vitaitis/)

[Justas Vitaitis](https://iproyal.com/blog/authors/justas-vitaitis/)

[Senior Software Engineer](https://iproyal.com/blog/authors/justas-vitaitis/)

Justas is a Senior Software Engineer with over a decade of proven expertise. He currently holds a crucial role in IPRoyal’s development team, regularly demonstrating his profound expertise in the Go programming language, contributing significantly to the company’s technological evolution. Justas is pivotal in maintaining our proxy network, serving as the authority on all aspects of proxies. Beyond coding, Justas is a passionate travel enthusiast and automotive aficionado, seamlessly blending his tech finesse with a passion for exploration.

[Learn More About Justas Vitaitis ](https://iproyal.com/blog/authors/justas-vitaitis/)[Meet all Writers](https://iproyal.com/blog/authors/)

Share on

### In This Article

- [What Is cURL and Why Use It to Download Files?](https://iproyal.com/blog/curl-download-file/#What-Is-cURL-and-Why-Use-It-to-Download-Files)
- [Basic Syntax to Download a File Using cURL](https://iproyal.com/blog/curl-download-file/#Basic-Syntax-to-Download-a-File-Using-cURL)
- [Downloading Files With cURL - Common Examples](https://iproyal.com/blog/curl-download-file/#Downloading-Files-With-cURL---Common-Examples)
- [Downloading Multiple Files With cURL](https://iproyal.com/blog/curl-download-file/#Downloading-Multiple-Files-With-cURL)
- [Handling Output and File Saving](https://iproyal.com/blog/curl-download-file/#Handling-Output-and-File-Saving)
- [Conclusion](https://iproyal.com/blog/curl-download-file/#Conclusion)

Ready to get started?

[Register now](https://dashboard.iproyal.com/register/)

Data News in Your Inbox

No spam whatsoever, just pure data gathering news, trending topics and useful links. Unsubscribe anytime.

No spam. Unsubscribe anytime.

## Related articles

[View all](https://iproyal.com/blog/category/tutorials/)

[Tutorials](https://iproyal.com/blog/the-most-common-payment-processing-obstacles-and-solutions-for-saas-companies/)

## [The Most Common Payment Processing Obstacles and Solutions for SaaS Companies](https://iproyal.com/blog/the-most-common-payment-processing-obstacles-and-solutions-for-saas-companies/)

[Here are the most common payment processing obstacles SaaS companies face and the solution that helped us focus on growth and our services!](https://iproyal.com/blog/the-most-common-payment-processing-obstacles-and-solutions-for-saas-companies/)

[August 8, 2022](https://iproyal.com/blog/the-most-common-payment-processing-obstacles-and-solutions-for-saas-companies/)

[3 min read](https://iproyal.com/blog/the-most-common-payment-processing-obstacles-and-solutions-for-saas-companies/)

[Tutorials](https://iproyal.com/blog/easy-programmatic-seo-with-wordpress/)

## [Easy Programmatic SEO with WordPress](https://iproyal.com/blog/easy-programmatic-seo-with-wordpress/)

[Our fourth and final entry in the pSEO series explains how to combine programmatic SEO with WordPress using plugins or code snippets.](https://iproyal.com/blog/easy-programmatic-seo-with-wordpress/)

[March 30, 2023](https://iproyal.com/blog/easy-programmatic-seo-with-wordpress/)

[10 min read](https://iproyal.com/blog/easy-programmatic-seo-with-wordpress/)

[Tutorials](https://iproyal.com/blog/api-for-dummies-the-coders-and-no-coders-guide/)

## [API for Dummies — The Coder’s and No-coder’s Guide](https://iproyal.com/blog/api-for-dummies-the-coders-and-no-coders-guide/)

[Learn API basics with this guide for coders and non-coders. Discover the different components of an API call.](https://iproyal.com/blog/api-for-dummies-the-coders-and-no-coders-guide/)

[June 1, 2023](https://iproyal.com/blog/api-for-dummies-the-coders-and-no-coders-guide/)

[11 min read](https://iproyal.com/blog/api-for-dummies-the-coders-and-no-coders-guide/)
