Is it possible to download using the Windows command line?
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.
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
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.
Windows 7 includes PowerShell and there's pretty much nothing you can't do with PowerShell.
Native alternative to wget in Windows PowerShell?
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') }"
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.