How to Use Wget to Download Files at Windows' Command Line

Download Files from the Windows Command Line with Wget
(Image credit: Tom's Hardware)

 

Most users will download files onto their PC using their web browser. There’s a problem with this method, however—it’s not particularly efficient. If you need to pause your download, or if you’ve lost your connection, you’ll probably need to start your download again from scratch. You may also be working with Python or other code at the command line and want to download directly from the command prompt. 

That’s where tools like Wget come in. This command line tool has a number of useful features, with support for recursive downloads and download resumption that allows you to download single files (or entire websites) in one go.

Wget is popular on Linux and other Unix-based operating systems, but it’s also available for Windows users. Below, we’ll explain how to install and use Wget to download any content you want online from your Windows command line.

Installing GNU Wget on Windows

Wget (in name, at least) is available on Windows 10 and 11 via the PowerShell terminal. However, this version of Wget isn’t the same as the GNU Wget tool that you’d use on a Linux PC. Instead, this version is simply an alias for a PowerShell command called Invoke-WebRequest.

Invoke-WebRequest is Wget-like in what it does, but it’s a completely different tool that’s much more difficult to use and understand. Instead, you’ll be better served by installing Wget for Windows, a compiled version of the same tool available for Linux users, using the steps below.

1. Download the Wget for Windows setup file from the Wget website. You’ll need to do this using your web browser.

2. Run the Wget for Windows installer file. Once the Wget setup file has finished downloading, run the setup file and follow the on-screen instructions to complete the installation.

(Image credit: Tom's Hardware)

3. Update the Wget.exe file (optional). The Wget installer is packaged with a fairly old version of the Wget binary. If you run into difficulties downloading files because of SSL certificate errors, you should download the latest wget.exe for your architecture from this website and save it to your Wget installation directory (typically C:\Program Files (x86)\GnuWin32\bin). This step is optional, but highly recommended.

(Image credit: Tom's Hardware)

4. Open the Start menu, search for environment variables, and click Open. Once the installation is finished, use the search tool in the Start menu to search for environment variables, then click Open. You’ll need to do this to allow you to use the ‘wget’ command from the command line without referencing its location every time you wish to run it.

(Image credit: Tom's Hardware)

5. Click Environment Variables in the System Properties window.

(Image credit: Tom's Hardware)

6. Select Path and click Edit under System or User variables.

(Image credit: Tom's Hardware)

7. Click the New button and type in the directory for the Wget for Windows binary (.exe) file. By default, this should be C:\Program Files (x86)\GnuWin32\bin.

(Image credit: Tom's Hardware)

8. Save your changes. When you’re finished, click OK in each menu and exit System Properties.

(Image credit: Tom's Hardware)

9. Open the Start menu, type cmd, and press Open. This will launch a new command prompt window.  You can also use the newer Terminal app, as long as you switch to using a command prompt shell.

(Image credit: Tom's Hardware)

10. Type wget --version and press Enter. If Wget was installed correctly, you should see the GNU Wget version returned in the command prompt window.

(Image credit: Tom's Hardware)

If you want to run Wget from a PowerShell terminal instead, you’ll need to run the file from its installation directory directly (eg. C:\Program Files (x86)\GnuWin32\bin\wget.exe).

Downloading Files with Wget

Once you’ve installed GNU Wget and you’ve configured the environment variables to be able to launch it correctly, you’ll be able to use it to start downloading files and webpages.

We’ve used an example domain and file path in our examples below. You’ll need to replace this with the correct path to the file (or files) that you want to download.

  • Type wget -h to see a full list of commands. This will give you the full list of options that you can use with Wget.
    wget -h

(Image credit: Tom's Hardware)

  • Download a single file using wget <url>. Replace <url> with the path to a file on an HTTP, HTTPS, or FTP server. You can also refer to a website domain name or web page directly to download that specific page (without any of its other content).
    wget example.com

(Image credit: Tom's Hardware)

  • Save with a different filename using -O. Using the -O option, you’ll be able to save the file with a different filename. For example, wget -O <filename> <url>, where <filename> is the filename you’ve chosen.
    wget -O example.html example.com

(Image credit: Tom's Hardware)

  • Save to a different directory using -P. If you want to save to another directory than the one you’re currently in, use the -P option. For example, wget -P <path> <url>.
    wget -P C:\folder example.com

(Image credit: Tom's Hardware)

  • Use --continue or -c to resume files. If you want to resume a partial download, use the -c option to resume it, as long as you’re in the same directory. For example, wget -c <url>.
    wget -c example.com

(Image credit: Tom's Hardware)

  • Download multiple files in sequence. If you want to download several files, add each URL to your Wget command. For example, wget <url1> <url2> etc.
    wget example.com tomshardware.com

(Image credit: Tom's Hardware)

  • Download multiple files using a text file with -i. Using the -i option, you can refer to a text file that contains a list of URLs to download a large number of files. Assuming that each URL is on a new line, Wget will download the content from each URL in sequence. For example, wget -i <file.txt> <url>.
    wget -i urls.txt

(Image credit: Tom's Hardware)

  • Limit download speeds using --limit-rate. If you want to limit your bandwidth usage, you can cap the download speeds using the --limit-rate option. For example, wget --limit-rate=1M <url> would limit it to 1 megabyte per second download speeds, while wget --limit-rate=10K <url> would limit it to 10 kilobytes per second.
    wget --limit-rate=10K example.com

(Image credit: Tom's Hardware)
  • Use -w or –wait to set a pause period after each download. If you’re downloading multiple files, using -w can help to spread the requests you make and help to limit any chance that your downloads are blocked. For example, wget -w 10 <url1> <url2> for a 10 second wait. 

wget -w 10 example.com tomshardware.com

(Image credit: Tom's Hardware)

  • Set a retry limit using -t or --tries. If a download fails, wget will use the -t value to determine how many times it’ll attempt it again before it stops. The default value is 20 retries. If the file is missing, or if the connection is refused, then this value is ignored and Wget will terminate immediately.
    wget -t 5 example.com

(Image credit: Tom's Hardware)

  • Save a log using -o or -a. You can save your log data to a text file using -o (to always create a new log file) or -a (to append to an existing file). For example, wget -o <file.txt> <url>.

(Image credit: Tom's Hardware)
  •  Bypass SSL errors using --no-check-certificate. If you’re having trouble downloading from a web server with an SSL certificate and you’ve already updated your Wget installation, bypass the SSL certificate check completely using --no-check-certificate to allow the download (in most cases). You should only do this for downloads from locations that you completely trust. For example, wget --no-check-certificate example.com. 

wget --no-check-certificate https://example.com

(Image credit: Tom's Hardware)

Make sure to use the wget -h or wget --help command to view the full list of options that are available to you. If you run into trouble with Wget, make sure to limit the number of retries you make and set a wait limit for each download you attempt.

Using Wget for Recursive Downloads

One of Wget’s most useful features is the ability to download recursively. Instead of only downloading a single file, it’ll instead try to download an entire directory of related files.

For instance, if you specify a web page, it’ll download the content attached to that page (such as images). Depending on the recursive depth you choose, it can also download any pages that are linked to it, as well as the content on those pages, any pages that are linked on those pages, and so on.

Theoretically, Wget can run with an infinite depth level, meaning it’ll never stop trying to go further and deeper with the content it downloads. However, from a practical point of view, you may find that most web servers will block this level of scraping, so you’ll need to tread carefully.

  • Type wget -r or wget --recursive to download recursively. By default, the depth level is five. For example, wget -r <url>.
    wget -r tomshardware.com

(Image credit: Tom's Hardware)

  • Use -l or –level to set a custom depth level. For example, wget -r -l 10 <url>. Use wget -r -l inf <url> for an infinite depth level.
    wget -r -l 10 tomshardware.com

(Image credit: Tom's Hardware)

  • Use -k to convert links to local file URLs. If you’re scraping a website, Wget will automatically convert any links in HTML to point instead to the offline copy that you’ve downloaded. For example, wget -r -k <url>.
    wget -r -k tomshardware.com

(Image credit: Tom's Hardware)

  • Use -p or --page-requisites to download all page content. If you want a website to fully download so that all of the images, CSS, and other page content is available offline, use the -p or --page-requisites options. For example, wget -r -p <url>.
    wget -r -p tomshardware.com

(Image credit: Tom's Hardware)

For a full list of options, make sure to use the wget --h command. You should also take care to respect any website that you’re actively downloading from and do your best to limit server loads using wait, retry, and depth limits.

If you run into difficulties with downloads because of SSL certificate errors, don’t forget to update your Wget binary file (wget.exe) with the latest version.

  • bit_user
    I always install Cygwin/X on any Windows PC I need to use. Then, just install wget through that way.
    https://x.cygwin.com/docs/ug/setup.html
    I find the default terminal very ugly and not UNIX-like in how it does copy/paste, so I use XLaunch to start the X11 server and then run everything from xterm. Just select to "copy" and middle-button pastes.
    Reply
  • brandonjclark
    bit_user said:
    I always install Cygwin/X on any Windows PC I need to use. Then, just install wget through that way.
    https://x.cygwin.com/docs/ug/setup.html
    I find the default terminal very ugly and not UNIX-like in how it does copy/paste, so I use XLaunch to start the X11 server and then run everything from xterm. Just select to "copy" and middle-button pastes.
    That all sounds REALLY complicated when WSL2 does a pretty great job.

    You can even integrate it with VSCode so you can code directly into the WSL2 instance! Try it out!

    a/kWh3jak
    Reply
  • bit_user
    brandonjclark said:
    That all sounds REALLY complicated when WSL2 does a pretty great job.
    Cygwin? Given that it's most of the userspace environment + components as you get on a typical Linux distro, it's really quite an easy and painless experience. I probably wouldn't install it just for wget, but that wasn't the point. The point is that I install it and get wget for "free".

    Probably the biggest benefit is that I can ssh w/ X tunneling and remotely run GUI programs on my Linux boxes.

    I have yet to try WSL2. There's no need, really. Unless I need to do something serious, it's hard for me to see how it would suit my needs any better than Cygwin/X.

    brandonjclark said:
    You can even integrate it with VSCode so you can code directly into the WSL2 instance! Try it out!
    But, I don't use VSCode. I already developed just fine, on Linux, without it. And I really don't like screen-filling IDEs. I open each file it its own editor window and run commands or the debugger from a separate xterm.
    Reply
  • brandonjclark
    bit_user said:
    Cygwin? Given that it's most of the userspace environment + components as you get on a typical Linux distro, it's really quite an easy and painless experience. I probably wouldn't install it just for wget, but that wasn't the point. The point is that I install it and get wget for "free".

    Probably the biggest benefit is that I can ssh w/ X tunneling and remotely run GUI programs on my Linux boxes.

    I have yet to try WSL2. There's no need, really. Unless I need to do something serious, it's hard for me to see how it would suit my needs any better than Cygwin/X.


    But, I don't use VSCode. I already developed just fine, on Linux, without it. And I really don't like screen-filling IDEs. I open each file it its own editor window and run commands or the debugger from a separate xterm.
    That's fair. Modern source control requirements aside (git integration), vscode really has a ton of creature comforts like a built-in terminal, plugins up the wazoo with support for just about anything, and is EXTREMELY customizable.
    Reply
  • paradyne
    On Windows 11 at least, maybe 10? Open command line / powershell.

    winget install wget
    Restart shell. Job done.
    Reply
  • bit_user
    brandonjclark said:
    Modern source control requirements aside (git integration), vscode really has a ton of creature comforts like a built-in terminal, plugins up the wazoo with support for just about anything, and is EXTREMELY customizable.
    I know people who use it and like it. No shade intended, but it doesn't suit my workstyle very well.

    As for git, I'm not the world's most sophisticated user, but I do alright with the commandline tool + the github web interface.
    Reply