Download files from the command line in Windows

Probably you will not need too often to download files from the command line/PowerShell, but in case you need, we will show here how you can archive this task.

In Linux, we have two commands to download files – wget and curl. Windows OS has the curl command. The curl command came to Windows in 2008.

To get the file content from the command line/PowerShell use curl URL

C:\Users\Web>curl plothost.com/kb
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://plothost.com/kb/">here</a>.</p>
</body></html>

C:\Users\Web>

To save the file on the local disk use curl URL -o local_filename

C:\Users\Web>curl http://plothost.com/test_file -o test_file.test
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 2054k  100 2054k    0     0   342k      0  0:00:06  0:00:06 --:--:--  420k

C:\Users\Web>

The -o option will output the content to a file instead of the terminal.

-o, –output Write to file instead of stdout

curl –help

To see all curl options, use curl –help.

If you are using Windows PowerShell, you can also use the Invoke-WebRequest command.

The Invoke-WebRequest cmdlet sends HTTP and HTTPS requests to a web page or web service. It parses the response and returns collections of links, images, and other significant HTML elements.

Invoke-WebRequest Doc

PS C:\Users\Web> Invoke-WebRequest http://plothost.com/test_file -o test_file.test
PS C:\Users\Web>
curl windows
curl command on Windows OS

Related articles:
Download files in Linux

Resources:
Invoke-WebRequest

Leave a Reply