134

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.

6
  • 6
    More ideas in "If the only browser in Windows is dead, how to connect to the Internet?" at superuser.com/questions/50427/…
    – Arjan
    Oct 23, 2009 at 15:16
  • And which out of the dozen Windows XP versions would that be?
    – Arjan
    Oct 23, 2009 at 15:17
  • Let's say it can be any windows XP SP2 version and everything released later. Oct 23, 2009 at 15:19
  • @arjan Interesting question, but there's still no definitive answer. Oct 23, 2009 at 15:19
  • I 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. :-)
    – Arjan
    Oct 23, 2009 at 15:35

17 Answers 17

54

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 
3
  • 1
    I 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/… :-)
    – Arjan
    Oct 23, 2009 at 15:37
  • that's if permission to cscript.exe is permitted Apr 2, 2015 at 11:23
  • I 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.
    – Wayfarer
    May 5, 2016 at 16:55
76

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.

14
  • 16
    it is part of windows7.
    – akira
    Aug 20, 2011 at 4:20
  • 3
    didn't work on my windows 7...
    – jyz
    Apr 5, 2012 at 0:14
  • 5
    This should have been the top-voted answer. bitsadmin is deprecated in favor of Windows powershell though.
    – lenkite
    May 14, 2012 at 9:04
  • 3
    Confirm working on Win7
    – kaiser
    Dec 10, 2012 at 7:41
  • 7
    Note: 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. Jan 1, 2013 at 20:33
40

Windows 7 includes PowerShell and there's pretty much nothing you can't do with PowerShell.

Native alternative to wget in Windows PowerShell?

5
  • 17
    (New-Object Net.WebClient).DownloadFile('someurl', 'somepath') Nov 17, 2011 at 2:52
  • 3
    Powershell is for Powerrangers ! How kool is that and why the heck didn't I know about this? Byebye cmd.
    – kaiser
    Dec 10, 2012 at 7:45
  • 18
    from cmd.exe: powershell -command "& { iwr http://www.it1.net/it1_logo2.jpg -OutFile logo.jpg }". also works from the run prompt Jun 3, 2014 at 11:57
  • 1
    Yeah, there's nothing you can't do without powershell. It's a real turing tarpit :) Oct 17, 2014 at 17:36
  • @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\")"
    – rogerdpack
    Aug 28, 2015 at 21:01
26

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') }"
4
  • 3
    @harrymc sure it's an answer. it downloads a file. what more do you want? Jun 3, 2014 at 11:55
  • 1
    (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.
    – harrymc
    Jun 3, 2014 at 12:34
  • What version of Windows and PowerShell is required for this to work? Jun 6, 2014 at 18:11
  • 2
    this doesn't work in Windows Server 2012 FYI, it throws a MethodInvocationException
    – knocte
    May 18, 2016 at 9:41
19

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.

2
  • I 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) Oct 23, 2009 at 15:15
  • 3
    Like 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.
    – DHayes
    Oct 23, 2009 at 15:17
14

Windows Explorer (not to be confused with Internet Explorer) can download files via HTTP. Just enter the URL into the Address bar. Or from the command line, for example, C:\windows\explorer.exe http://somewhere.com/filename.ext.

You get the classic File Download prompt. Unless the file is a type that Windows Explorer knows how to display inline, (.html, .jpg, .gif), in which case you would then need to right-click to save it.

I just tested this on my VMware image of a virgin install of Windows XP 2002 SP1, and it works fine.

3
  • 4
    this requires user interaction. probably not what most people who want to download a file from the command prompt want
    – Kip
    Nov 14, 2012 at 20:14
  • Nowadays, 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! Nov 2, 2016 at 2:57
  • This just calls up iexplorer.exe (by default) and additionally requires the site to be added to security exceptions on server installations.
    – Scott P.
    Aug 12, 2022 at 18:34
7

You can use (in a standard Windows bat):

powershell -command "& { iwr http://www.it1.net/it1_logo2.jpg -OutFile logo.jpg }"

It seems to require PowerShell v4...

(Thanks to that comment and this one)

6

Use FTP.

From the command line:

ftp ftp.somesite.com
user
password

etc. FTP is included in every Windows version I can remember; probably not in 3.1, maybe not in Windows 95, but certainly everything after that.

@RM: It is going to be rough if you don't want to download any other tools. There exists a command line Wget for Windows and Wget is designed to do exactly what you're asking for.

4
  • +1 good answer. ftp is pretty universal, as long as the server you're trying to download from supports it. Oct 23, 2009 at 15:05
  • Thank you, sorry I wasn't more specific, I meant using HTTP. Oct 23, 2009 at 15:10
  • 1
    This 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). Apr 5, 2016 at 21:04
  • @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. Apr 6, 2016 at 19:32
5

Use PowerShell like this:

  1. Create a download.ps1 file:

    param($url, $filename)
    $client = new-object System.Net.WebClient 
    $client.DownloadFile( $url, $filename)
    
  2. Now you can download a file like this:

    powershell Set-ExecutionPolicy Unrestricted
    powershell -ExecutionPolicy RemoteSigned -File "download.ps1" "http://somewhere.com/filename.ext" "d:\filename.ext"
    
1
  • This works, even on Windows XP 64-bit, PowerShell 2.0. Apr 5, 2016 at 21:13
3

On Win CMD (if you have write access):

set url=https://www.nsa.org/content/hl-images/2017/02/09/NSA.jpg
set file=file.jpg
certutil -urlcache -split -f %url% %file%
echo Done.

Built in Windows app. No need for external downloads.

Tested on Win 10

2

If you have python installed here's an example which fetches the get-pip.py from the web

python -c "import urllib; urllib.urlretrieve ('https://bootstrap.pypa.io/get-pip.py', r'C:\python27\Tools\get-pip.py')"
0
2

File can be download via below method

bitsadmin /transfer wcb /priority high https://sustainabledevelopment.un.org/content/documents/Agenda21.pdf C:\Program Files (x86)\Dell Update\Agenda21.pdf

2

From Windows 10 build 17063 and later, ‘Curl’ is now included, so that you can execute it directly from Cmd.exe or PowerShell.exe.

For example:

C:\>curl.exe -V
curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL
Release-Date: 2017-11-14, security patched: 2019-11-05
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL

To download a file:

curl.exe -O https://cdn.sstatic.net/Sites/superuser/Img/logo.svg
1

If you install Telnet, I imagine you could make a HTTP request to a server to download a file.

You can also install Cygwin, and use wget to download a file as well. This is a very easy way to download files from the command line.

10
  • 3
    I'm pretty sure 'cygwin' counts as a non-standard utility ;-) Oct 23, 2009 at 15:04
  • Telnet 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? Oct 23, 2009 at 15:05
  • Install telnet? Telnet is like ftp; it comes with windows. Don't know about redirecting the output though. Oct 23, 2009 at 15:10
  • For 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
    Oct 23, 2009 at 15:21
  • 1
    Why install cygwin just to use wget? There is a native win32 binary available.
    – innaM
    Oct 23, 2009 at 15:39
1

There are a few ways that you can download using the command line in Windows:

  1. You can use Cygwin.

    Note: the included apps are not native Linux apps. You must rebuild your application from source if you want to run on Windows.

  2. Using telnet it's possible to make a request but you won't see any processing.

  3. You can write bat or VBS scripts.

  4. Write your own program that you can run from cmd.exe.

1

You can install the Linux application Wget on Windows. It can be downloaded from http://gnuwin32.sourceforge.net/packages/wget.htm. You can then issue the command 'wget (inserturlhere)' or any other URL in your command prompt, and it will allow you to download that URL/file/image.

1
  • 1
    Strangely 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
    – sinni800
    May 16, 2011 at 12:17
0

In default Windows, you can't download via HTTP. Windows is a GUI-centric OS, so it lacks many of the commandline tools you'd find in other OS's, like wget, which would be the prime candidate.

System.Net.WebClient.DownloadFile(), a function in the WiniNet API, can download files, but I'm not sure how far you're getting into actual development vs. a batch file.

1
  • I understand it's possible using wget, but my question states without the use non-standard windows utils. Oct 23, 2009 at 15:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .