Is it possible to download using the Windows command line?
Solution 1
You can write a VBScript and run it from the command line
Create a file downloadfile.vbs
and insert the following lines of code:
' Set your settings
strFileURL = "http://www.it1.net/images/it1_logo2.jpg"
strHDLocation = "c:\logo.jpg"
' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
Set objFSO = Nothing
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if
Set objXMLHTTP = Nothing
Run it from the command line as follows:
cscript.exe downloadfile.vbs
Solution 2
Starting with Windows 7, I believe there's one single method that hasn't been mentioned yet that's easy:
Syntax:
bitsadmin /transfer job_name /download /priority priority URL local\path\file
Example:
bitsadmin /transfer mydownloadjob /download /priority normal ^ http://example.com/filename.zip C:\Users\username\Downloads\filename.zip
(Broken into two separate lines with ^
for readability
(to avoid scrolling).)
Warning: As pointed out in the comments,
the bitsadmin
help message starts by saying:
BITSAdmin is deprecated and is not guaranteed to be available in future versions of Windows.
Administrative tools for the BITS service are now provided by BITS PowerShell cmdlets.
... but another comment reported that it works on Windows 8.
Solution 3
Windows 7 includes PowerShell and there's pretty much nothing you can't do with PowerShell.
Native alternative to wget in Windows PowerShell?
Solution 4
PowerShell (included with Windows 8 and included with .NET for earlier releases) has this capability. The powershell
command allows running arbitrary PowerShell commands from the command line or a .bat
file. Thus, the following line is what's wanted:
powershell -command "& { (New-Object Net.WebClient).DownloadFile('http://example.com/', 'c:\somefile') }"
Solution 5
I found a way of doing it, but really, just install Wget.
You can use Internet Explorer from a command line (iexplore.exe) and then enter a URL as an argument. So, run:
iexplore.exe http://blah.com/filename.zip
Whatever the file is, you'll need to specify it doesn't need confirmation ahead of time. Lo and behold, it will automatically perform the download. So yes, it is technically possible, but good lord do it in a different way.
Comments
-
Robert Massa over 1 year
Without using any non-standard (Windows included) utilities, is it possible to download using the Windows command line?
The preferred version is Windows XP, but it's also interesting to know for newer versions.
To further clarify my question:
- It has to be using HTTP
- The file needs to be saved
- Standard clean Windows install, no extra tools
So basically, since everybody is screaming Wget, I want simple Wget functionality, without using Wget.
-
Arjan over 14 yearsMore ideas in "If the only browser in Windows is dead, how to connect to the Internet?" at superuser.com/questions/50427/…
-
Arjan over 14 yearsAnd which out of the dozen Windows XP versions would that be?
-
Robert Massa over 14 yearsLet's say it can be any windows XP SP2 version and everything released later.
-
Robert Massa over 14 years@arjan Interesting question, but there's still no definitive answer.
-
Arjan over 14 yearsI should have asked for "edition". Like Starter, Home, Professional, Media Center, Tablet, maybe even Embedded (good change for tools there I guess!)... Or the European versions without Windows Media Player. :-)
-
Anderson Green about 11 yearsMore answers to this question can be found here: stackoverflow.com/questions/4619088/…
-
DaveParillo over 14 yearsI'm pretty sure 'cygwin' counts as a non-standard utility ;-)
-
DaveParillo over 14 years+1 good answer. ftp is pretty universal, as long as the server you're trying to download from supports it.
-
Robert Massa over 14 yearsTelnet is an interesting option, is there a way to pipe the output to a file without corrupting it? And can we pipe HTTP GET command into telnet to make the request?
-
Robert Massa over 14 yearsI understand it's possible using wget, but my question states without the use non-standard windows utils.
-
Satanicpuppy over 14 yearsInstall telnet? Telnet is like ftp; it comes with windows. Don't know about redirecting the output though.
-
Robert Massa over 14 yearsI know wget is a much better way, it's just a hypothetical question ;) Your answer comes pretty close, but still requires user intervention(clicking "Save", or configuring not to display this dialog)
-
DHayes over 14 yearsLike I said, you have to deselect the option to prompt to save for that file type. For example, download a zip file, disable that prompt, and then in the future any zip files accessed from the command line will automatically save.
-
Arjan over 14 yearsFor XP (as in the question) telnet is installed by default, but I heard that on Vista that's no longer the case? But no, it does not allow for file downloads, unless all is returned in a single HTTP response, and one can strip the headers and decode the stuff on the command line as well. Quite unlikely one can control that.
-
Arjan over 14 yearsI wonder if this relies on Internet Explorer, but I guess this would be a fine answer for "If the only browser in Windows is dead, how to connect to the Internet?" at superuser.com/questions/50427/… :-)
-
innaM over 14 yearsWhy install cygwin just to use wget? There is a native win32 binary available.
-
EvilChookie over 14 years@DaveParillo: My answer was posted before the requirements of clean install. @Robert: I'm not sure. I've never used telnet in this fashion. I said 'I imagine you could'. @SatanicPuppy: As Arjan pointed out, it's not in Vista by default. @Manni: I did not know there was a win32 binary available.
-
sinni800 about 13 yearsStrangely this version is not always compatible. On my Windows 7 computer it wasn't because libraries were missing. You'd want to use wget without any extra libraries most of the time. users.ugent.be/~bpuype/wget
-
Reed Hedges almost 13 yearsThis looks like the kind of tool the OP was looking for, but it is not a standard part of a Windows install, you have to install it separately. Useful tool though.
-
akira almost 13 yearsit is part of windows7.
-
user1533603 over 12 years(New-Object Net.WebClient).DownloadFile('someurl', 'somepath')
-
jyz about 12 yearsdidn't work on my windows 7...
-
lenkite about 12 yearsThis should have been the top-voted answer. bitsadmin is deprecated in favor of Windows powershell though.
-
Furqat Ubaydullayev over 11 yearsIt was part of my windows 7 install. Thanks!
-
Kip over 11 yearsthis requires user interaction. probably not what most people who want to download a file from the command prompt want
-
Luigi Ranghetti over 11 yearsConfirm working on Win7
-
TrickyDBA over 11 yearsNote: BITSAdmin is deprecated and is not guaranteed to be available in future versions of Windows. Administrative tools for the BITS service are now provided by BITS PowerShell cmdlets.
-
user2428118 over 10 years@EvilChookie Telnet comes with Windows Vista+, it simply isn't enabled by default in these versions of Windows.
-
barlop almost 10 years@jyzuz It is part of Windows 7 Ultimate. I don't know what you have.
-
barlop almost 10 years@user2428118 the telnet service exists sure, but the telnet CLIENT does not exist in Win7, telnet.exe it can be copied from XP though.
-
barlop almost 10 yearsI have a strange telnet.exe on win7 32bit ultimate here C:\Windows\winsxs\x86_microsoft-windows-telnet-client_31bf3856ad364e35_6.1.7600.16385_none_b807e788865dfff7> and similar on a win7 64bit ultimate C:\Windows\winsxs\amd64_microsoft-windows-telnet-client_31bf385 0.16385_none_1426830c3ebb712d> but it/they don't do anything. A working telnet.exe has to be copied from XP
-
user2428118 almost 10 years@barlop The client does exist. You can just go to here and enable the Telnet client.
-
Janus Troelsen almost 10 years@harrymc sure it's an answer. it downloads a file. what more do you want?
-
Janus Troelsen almost 10 yearsfrom cmd.exe:
powershell -command "& { iwr http://www.it1.net/it1_logo2.jpg -OutFile logo.jpg }"
. also works from the run prompt -
harrymc almost 10 years(1) Some text to explain what does this one-liner, (2) Verify that your answer isn't an alternative formulation to a previous answer, since if it is, it should at most be expressed as a comment on that answer.
-
Peter Mortensen almost 10 yearsWhat version of Windows and PowerShell is required for this to work?
-
jcarpenter2 over 9 yearsYeah, there's nothing you can't do without powershell. It's a real turing tarpit :)
-
Vaibhav Garg over 9 yearsDoesn't run from a Batch file via task scheduler. I get this error:
Unable to add file - 0x800704dd The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist.
-
hello_there_andy about 9 yearsthat's if permission to cscript.exe is permitted
-
hello_there_andy about 9 yearsConfirm working on this Win8
-
hello_there_andy about 9 years@VaibhavGarg you need to make sure the name of the downloaded file is exactly as appears on the last part of the download URL (after the final '/' and preceding, say, the '.exe')
-
rogerdpack over 8 years@JanusTroelsen my version of PowerShell responded "The term 'iwr' is not recognized as the name of a cmdlet,..." but after some investigation this similar worked:
powershell -command "$clnt = new-object System.Net.WebClient; $clnt.DownloadFile(\"https://host/name\", \"outpufilename\")"
-
kgadek over 8 yearsIt's present in Win10… though doesn't handle FTP protocol :(
-
Peter Mortensen about 8 yearsThis will not work with most FTP servers as passive mode is not supported by this Windows ftp client (with NATs inbetween passive mode is required).
-
Peter Mortensen about 8 yearsThis works, even on Windows XP 64-bit, PowerShell 2.0.
-
Satanicpuppy about 8 years@PeterMortensen It also doesn't remotely answer the question since he edited it to specify he was looking for wget functionality. But don't let that stop you from resurrecting a 7 year old wrong answer just to add some pedantry.
-
Wayfarer about 8 yearsI can confirm that I have tested this script in Windows PE 5.1 and it has worked like a charm. I intend to use it for offline deployment, in order to check the version of the platform in the USB drive against a text file stored on the server.
-
knocte about 8 yearsthis doesn't work in Windows Server 2012 FYI, it throws a MethodInvocationException
-
kayleeFrye_onDeck over 7 yearsNowadays, it depends on your default-browser. Mine is chrome, and it auto-downloads to a known location, so I consider this solution to be sufficient for my needs. Thx!
-
amenthes about 6 yearsIt's not present on my Win10 - at least not in safe mode.
-
DimiDak about 3 yearsMust be the only answer in the whole internet about using cmd to download a file without powershell or the need to install tools like curl and wget.