Home » Questions » Computers [ Ask a new question ]

How to download files from command line in Windows like wget or curl

How to download files from command line in Windows like wget or curl

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

Asked by: Guest | Views: 437
Total answers/comments: 5
bert [Entry]

"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://eternallyboreddotorg/misc/wget/
from sourceforge: http://gnuwin32.sourceforge.net/packages/wget.htm
[...]


Link with courtesy of Jernej Simončič is used instead."
bert [Entry]

"cURL

Windows 10 includes curl.exe:

techcommunity.microsoft.com/t5/containers/-/ba-p/382409

so you can do something like this:

# example 1
curl.exe --output index.html --url superuser.com
# example 2
curl.exe -o index.html superuser.com

If you have older Windows, you can still download it:

curl.haxx.se/windows

PowerShell
# example 1
Invoke-WebRequest -OutFile index.html -Uri superuser.com
# example 2
iwr -outf index.html superuser.com

docs.microsoft.com/powershell/module/microsoft.powershell.utility/invoke-webrequest"
bert [Entry]

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

@Echo OFF
SetLocal EnableDelayedExpansion
Set Var=%1
Set Var=!Var:http://=!
Set Var=!Var:/=,!
Set Var=!Var:%%20=?!
Set Var=!Var: =?!
Call :LOOP !var!
Echo.Downloading: %1 to %~p0!FN!
powershell.exe -Command (new-object System.Net.WebClient).DownloadFile('%1','%~p0!FN!')
GoTo :EOF
:LOOP
If ""%1""=="""" GoTo :EOF
Set FN=%1
Set FN=!FN:?= !
Shift
GoTo :LOOP

I borrowed some code from Parsing URL for filename with space."
"I made a quick myGet.bat file which calls the PowerShell method described above.

@Echo OFF
SetLocal EnableDelayedExpansion
Set Var=%1
Set Var=!Var:http://=!
Set Var=!Var:/=,!
Set Var=!Var:%%20=?!
Set Var=!Var: =?!
Call :LOOP !var!
Echo.Downloading: %1 to %~p0!FN!
powershell.exe -Command (new-object System.Net.WebClient).DownloadFile('%1','%~p0!FN!')
GoTo :EOF
:LOOP
If ""%1""=="""" GoTo :EOF
Set FN=%1
Set FN=!FN:?= !
Shift
GoTo :LOOP

I borrowed some code from Parsing URL for filename with space."
bert [Entry]

"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 “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."
bert [Entry]

"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."