Use Curl To Download A File

Learn how to download any file using command line from internet or FTP servers to your Linux server. Tips & Tricks Tagged With: download file using command line, how to download file in linux, how to download file using curl, how to download files using command line, w3m tool, wget tool. If you like my tutorials and if they helped you in. CURL stands for command Line URL and is a simple, yet powerful, command line utility that gives the ability to download content using a lightweight executable that provides cross-platform support. CURL is community supported and is often a packaged part of some *nix systems already.

How can I download something from the web directly without Internet Explorer or Firefox opening Acrobat Reader/Quicktime/MS Word/whatever?

I'm using Windows, so a Windows version of Wget would do.


Use Curl To Download A File

19 Answers

Wget for Windows should work.

From the Wget Wiki FAQ:

GNU Wget is a free network utility to retrieve files from the World Wide Web using HTTP and FTP, the two most widely used Internet protocols. It works non-interactively, thus enabling work in the background, after having logged off.

From this section of FAQ, download links are suggested:

Windows Binaries

  • courtesy of Jernej Simončič: http://eternallybored.org/misc/wget/

  • from sourceforge: http://gnuwin32.sourceforge.net/packages/wget.htm

  • [...]

Link with courtesy of Jernej Simončič is used instead.


An alternative I discovered recently, using PowerShell:

It works as well with GET queries.

If you need to specify credentials to download the file, add the following line in between:

A standard windows credentials prompt will pop up. The credentials you enter there will be used to download the file. You only need to do this once for all the time you will be using the $client object.


If you have PowerShell >= 3.0, you can useInvoke-WebRequest

Or golfed


Windows has its own command line download utility - BITSAdmin:

BITSAdmin is a command-line tool that you can use to create download or upload jobs and monitor their progress.

EDIT: 26.01.15 - Here's my overview of how a file can be downloaded on windows without external tools

And a complete bitsadmin example:

Edit : 15.05.2018 - turned out that's possible to download a file with certutil too:

Certutil is not installed by default on XP/Win2003 but is avaialble on the newer windows versions.For XP/2003 you'll need the Admin Tool Pack for windows server 2003


Save the following text as wget.js and simply call

This is the code:


There is a native cURL for Windows available here. There are many flavors available- with and without SSL support.

You don't need the extra baggage of Cygwin and the likes, just one small EXE file.

It is also important to know that there are both wget and curl aliases built into all modern versions of Windows Powershell. They are equivalent.

No extra files or downloads are required to obtain wget functionality:

Using Curl In Powershell (The Sociable Geek)

Excerpt:

You can type in a cURL command like one that downloads a file from a GitHub repository.

curl http://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/mongodb-on-ubuntu/azuredeploy.json

and it will seem like it works but what it is actually doing is just using cURL as an alias. In the above instance, what will happen is that you will just get the headers instead of the file itself.

Aliases in PowerShell allow you to create shortcuts for longer commands so you don’t have to type them out all of the time.

If you type in the command Get-Alias, it will give you a list of all the Aliases that are used in PowerShell. As you can see, the curl command just calls the Invoke-WebRequest command. They are similar but not the same which is why the above request does not work for us.

To get this to work properly in PowerShell the easiest way is to use variables and the -OutFile argument as shown here:

(file name cut off in image “https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/mongodb-on-ubuntu/azuredeploy.json”)

This syntax will download the full contents of the target file azuredeploy.json to the local file newfile.json

The primary advantage is that it is built into Powershell itself so this code will execute directly with no downloads or any other extra file creations are required to make it work on any modern version of Windows.


Curl Download Complex Url

I made a quick myGet.bat file which calls the PowerShell method described above.

I borrowed some code from Parsing URL for filename with space.


I was searching for the same, and since I had no privilege to install any of the above packages, I went for a small workaround (to download 30+files):

  • I created a batch file
  • Listed all the files
  • Put firefox.exe at the beginning of each line
  • Went to the firefox directory in Program Files
  • Ran it.

If PowerShell is an option, that's the preferred route, since you (potentially) won't have to install anything extra:

Failing that, Wget for Windows, as others have pointed out is definitely the second best option. As posted in another answer it looks like you can download Wget all by itself, or you can grab it as a part of Cygwin or MSys.

If for some reason, you find yourself stuck in a time warp, using a machine that doesn't have PowerShell and you have zero access to a working web browser (that is, Internet Explorer is the only browser on the system, and its settings are corrupt), and your file is on an FTP site (as opposed to HTTP):

If memory serves it's been there since Windows 98, and I can confirm that it is still there in Windows 8 RTM (you might have to go into appwiz.cpl and add/remove features to get it). This utility can both download and upload files to/from FTP sites on the web. It can also be used in scripts to automate either operation.

This tool being built-in has been a real life saver for me in the past, especially in the days of ftp.cdrom.com -- I downloaded Firefox that way once, on a completely broken machine that had only a dial-up Internet connection (back when sneakernet's maximum packet size was still 1.44 MB, and Firefox was still called 'Netscape' /me does trollface).

A couple of tips: it's its own command processor, and it has its own syntax. Try typing 'help'. All FTP sites require a username and password; but if they allow 'anonymous' users, the username is 'anonymous' and the password is your email address (you can make one up if you don't want to be tracked, but usually there is some kind of logic to make sure it's a valid email address).



And http://www.httrack.com/ has a nice GUI (and it's free), for mirroring sites. It also has a Linux version.


You could also use the wget packaged in PowerShell. ;^) To open, hit the Windows key and type 'powershell' or Windows-R and type 'powershell' and hit return.

No installation necessary.

One interesting difference from conventional wget (more at that link): You can't simply use the greater-than to pipe to a file. wget in PowerShell is just a convenience wrapper for Invoke-WebRequest, and you need to use its syntax to write to a file.


You can get WGet for Windows here. Alternatively you can right click on the download link of the item you want to download and choose Save As. This will download the file and not open it in the assigned application.


I think installing wget via Chocolatey is the easiest way.

  1. Install Chocolatey
  2. From the command-line, type: choco install wget
  3. You can then use wget from the command line like on *nix systems.

Search for /download function on https://lolbas-project.github.io.

Right now there are Bitsadmin.exe, Certutil.exe, Esentutl.exe, Expand.exe, Extrac32.exe, Findstr.exe, Hh.exe, Ieexec.exe, Makecab.exe, Replace.exe for Windows vista, Windows 7, Windows 8, Windows 8.1, Windows 10 and the equivalent Server versions.


If you want a GUI, then try VisualWget, which is actually clean, and feature full. It is based on GNU Wget for its download engine.

EDIT: updated link.


As documented in this SU answer, you can use the following in Powershell:


An alternative to using gnuwin32 is unxutils which includes wget.


If you need a visual Post for Windows, here is one.
You can post data or files with it.


protected by NifleNov 10 '14 at 9:49

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged windowswgetcurl or ask your own question.

For downloading files directly from the Linux command line, there are two utilities that immediately come to mind: wget and cURL. They share a lot of features and can easily get many of the same tasks accomplished.

Though they share similar features, they aren’t exactly the same. These programs fit slightly different roles and use cases, and do have traits that make each better for certain situations.

cURL vs wget: Their Similarities

Both wget and cURL can download things. At their core, that’s what they both do. They can make requests of the Internet and pull back the requested item. That could be a file, picture, or even the raw HTML of a website.

Both programs are also capable of making HTTP POST requests. This means they can send data to a website, like filling out a form.

Since both are command line tools, they were also both designed to be scriptable. You can include both wget and cURL in your Bash scripts to automatically interact with online content and retrieve what you need.

wget Advantages

Use Curl To Download A File For Windows 7

Download

wget is simple and straightforward. It’s meant for quick downloads, and it’s excellent at it. wget is a single self-contained program. It doesn’t require any extra libraries, and it’s not meant to do anything beyond the scope of what it does.

Because wget is so tailored for straight downloads, it also has the ability to download recursively. That allows you to download everything on a page or all of the files in an FTP directory at once.

wget also has intelligent defaults. It specifies how to handle a lot of things that a normal browser would, like cookies and redirects, without the need to add any configuration. Lastly, wget works out of the box.

cURL Advantages

cURL is a multi-tool. Sure, it can download content from the Internet. It can do a lot more, too.

cURL is powered by a library: libcurl. This means you can write entire programs based on cURL, allowing you to base graphical download pograms on libcurl and get access to all of its functionality.

The wide range or protocols that cURL supports are probably the biggest selling point it has. cURL can access websites over HTTP and HTTPS and can handle FTP in both directions. It supports LDAP and even Samba shares. You can actually use cURL to send and retrieve email.

cURL has some neat security features, too. cURL supports loads of SSL/TLS libraries. It also supports Internet access via proxies, including SOCKS. That means you can use cURL over Tor.

cURL also supports gzip compression to send large amounts of data more easily.

Closing Thoughts

So should you use cURL or wget? That really depends. If you want to download something quickly without needing to worry about flags, then you should go with wget. It’s simple and just works. If you want to do something more complex, cURL should be your immediate choice.

cURL allows you to do a lot more. You can think of cURL like a stripped-down command line web browser. It supports just about every protocol you can think of and can access and interact with nearly all online content. The only is that a browser renders the responses that it receives, and cURL doesn’t.

Ebooks