Download File Command Line Windows

I am trying to download a file from a website (ex. http://www.example.com/package.zip) using a Windows batch file. I am getting an error code when I write the function below:

The batch file doesn't seem to like the '/' after the http. Are there any ways to escape those characters so it doesn't assume they are function parameters?

Line

Download A Single File from FTP. To download the file from FTP server, we use get command. Using that command we can download one time at a time. To download any file from FTP server First login to your FTP server, navigate to the directory and use the following command to download. Ftp> get file1.txt 4. Upload Multiple Files to FTP. Downloading file(s) using the Command Prompt is a great idea if you’re looking to do some COOL things. It is also useful if you don’t want to use third party programs for downloading files.

JamesJames

18 Answers

With PowerShell 2.0 (Windows 7 preinstalled) you can use:

Starting with PowerShell 3.0 (Windows 8 preinstalled) you can use Invoke-WebRequest:

From a batch file they are called:

(PowerShell 2.0 is available for installation on XP, 3.0 for Windows 7)

sevenforcesevenforce

There's a standard Windows component which can achieve what you're trying to do: BITS. It has been included in Windows since XP and 2000 SP3.

Run:

The job name is simply the display name for the download job - set it to something that describes what you're doing.

brainwoodbrainwood

This might be a little off topic, but you can pretty easily download a file using Powershell. Powershell comes with modern versions of Windows so you don't have to install any extra stuff on the computer. I learned how to do it by reading this page:

The code was:

David GraysonDavid Grayson

Last I checked, there isn't a command line command to connect to a URL from the MS command line. Try wget for Windows:
http://gnuwin32.sourceforge.net/packages/wget.htm

or URL2File:
http://www.chami.com/free/url2file_wincon.html

In Linux, you can use 'wget'.

Alternatively, you can try VBScript. They are like command line programs, but they are scripts interpreted by the wscript.exe scripts host. Here is an example of downloading a file using VBS:
https://serverfault.com/questions/29707/download-file-from-vbscript

LostInTheCodeLostInTheCode
Kalpesh SoniKalpesh Soni

Downloading files in PURE BATCH...

Without any JScript, VBScript, Powershell, etc... Only pure Batch!

Some people are saying it's not possible of downloading files with a batch script without using any JScript or VBScript, etc... But they are definitely wrong!

Here is a simple method that seems to work pretty well for downloading files in your batch scripts. It should be working on almost any file's URL. It is even possible to use a proxy server if you need it.

For downloading files, we can use BITSADMIN.EXE from the Windows system. There is no need for downloading/installing anything or using any JScript or VBScript, etc. Bitsadmin.exe is present on most Windows versions, probably from XP to Windows 10.

Enjoy!

USAGE:

You can use the BITSADMIN command directly, like this:
bitsadmin /transfer mydownloadjob /download /priority normal 'http://example.com/File.zip' 'C:DownloadsFile.zip'

Proxy Server:
For connecting using a proxy, use this command before downloading.
bitsadmin /setproxysettings mydownloadjob OVERRIDE 'proxy-server.com:8080' '<local>'

Click this LINK if you want more info about BITSadmin.exe

CUSTOM FUNCTIONS
:DOWNLOAD_FILE 'URL'
:DOWNLOAD_PROXY_ON 'SERVER:PORT'
:DOWNLOAD_PROXY_OFF

I made these 3 functions for simplifying the bitsadmin commands. It's easier to use and remember. It can be particularly useful if you are using it multiple times in your scripts.

PLEASE NOTE...
Before using these functions, you will first need to copy them from CUSTOM_FUNCTIONS.CMD to the end of your script. There is also a complete example: DOWNLOAD-EXAMPLE.CMD

:DOWNLOAD_FILE 'URL'
The main function, will download files from URL.

:DOWNLOAD_PROXY_ON 'SERVER:PORT'
(Optional) You can use this function if you need to use a proxy server.
Calling the :DOWNLOAD_PROXY_OFF function will disable it.

EXAMPLE:
CALL :DOWNLOAD_PROXY_ON 'proxy-server.com:8080'
CALL :DOWNLOAD_FILE 'http://example.com/File.zip' 'C:DownloadsFile.zip'
CALL :DOWNLOAD_PROXY_OFF

CUSTOM_FUNCTIONS.CMD

DOWNLOAD-EXAMPLE.CMD

Frank EinsteinFrank Einstein

AFAIK, Windows doesn't have a built-in commandline tool to download a file. But you can do it from a VBScript, and you can generate the VBScript file from batch using echo and output redirection:

More explanation here

AbscissaAbscissa
  1. Download Wget from here http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-setup.exe

  2. Then install it.

  3. Then make some .bat file and put this into it

  4. Adjust the URL and the file path in the script

  5. Run the file and profit!
boksioraboksiora

You cannot use xcopy over http. Try downloading wget for windows. That may do the trick. It is a command line utility for non-interactive download of files through http. You can get it at http://gnuwin32.sourceforge.net/packages/wget.htm

Matt WrockMatt Wrock

If bitsadmin isn't your cup of tea, you can use this PowerShell command:

TrinitrotolueneTrinitrotoluene

Use Bat To Exe Converter
Create a batch file and put something like the code below into it

or

and convert it to exe.

kentuckyschreitkentuckyschreit

BATCH may not be able to do this, but you can use JScript or VBScript if you don't want to use tools that are not installed by default with Windows.

The first example on this page downloads a binary file in VBScript:http://www.robvanderwoude.com/vbstech_internet_download.php

This SO answer downloads a file using JScript (IMO, the better language):Windows Script Host (jscript): how do i download a binary file?

Your batch script can then just call out to a JScript or VBScript that downloads the file.

Community
aikeruaikeru

This should work i did the following for a game server project. It will download the zip and extract it to what ever directory you specify.

Save as name.bat or name.cmd

Original : https://github.com/C0nw0nk/SteamCMD-AutoUpdate-Any-Gameserver/blob/master/steam.cmd

C0nw0nkC0nw0nk

Instead of wget you can also use aria2 to download the file from a particular URL.

See the following link which will explain more about aria2:

SasikumarSasikumar

I found this VB script:

Works like a charm. Configured as a function with a very simple function call:

Originally from: http://www.ericphelps.com/scripting/samples/BinaryDownload/index.htm

Here is the full code for redundancy:

BeachhouseBeachhouse

This question has very good answer in here. My code is purely based on that answer with some modifications.

Save below snippet as wget.bat and put it in your system path (e.g. Put it in a directory and add this directory to system path.)

You can use it in your cli as follows:

wget url/to/file [?custom_name]

where url_to_file is compulsory and custom_name is optional

  1. If name is not provided, then downloaded file will be saved by its own name from the url.
  2. If the name is supplied, then the file will be saved by the new name.

The file url and saved filenames are displayed in ansi colored text. If that is causing problem for you, then check this github project.

P.S. This code requires you to have PowerShell installed.

Community
bantyabantya
Windows

You can setup a scheduled task using wget, use the “Run” field in scheduled task as:

lv10lv10

use ftp:

Change everything in asterisks to fit your situation.

user212218
Kirill ShilovKirill Shilov

protected by CommunityJun 17 '17 at 14:02

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged windowsbatch-filedownloadscripting or ask your own question.

RECOMMENDED: Click here to fix Windows errors and improve PC performance

Majority of Windows users will never need to open Command Prompt as administrator or elevated Command Prompt as many of the commands can be executed without the elevated Command Prompt.

That said, there are some tasks that can only be performed from Command Prompt running with administrator rights, and you get “You may not have permission to perform this operation” or “Access is denied” error when you try to execute certain commands without admin rights.

In Windows 10, there are a bunch of ways to open Command Prompt as administrator or run elevated Command Prompt. You can follow one of the below mentioned methods to launch Command Prompt as administrator in Windows 10.

NOTE: If you’re wondering how to know that the Command Prompt has been launched as administrator, it’s easy. When the Command Prompt is launched with admin rights, “Administrator” text will appear on the titlebar (see the above picture) of the Command Prompt window.

Windows Command Line Download File From Url

Anyways, below are the methods to open Command Prompt as administrator in Windows 10.

Method 1 of 6

Use shortcut keys to quickly open elevated Command Prompt

This is probably the easiest and fastest method out there to open Command Prompt as administrator.

Step 1: Press the Windows logo key on the keyboard or simply click/tap the Windows logo button on the bottom-left corner of the screen to open the Start.

Step 2: Type CMD in the Start/taskbar search box (search box is automatically selected when you open Start) or in the Run command box, and then simultaneously press Ctrl+Shift+Enter keys.

Step 3: Click the Yes button when you see the User Account Control dialog box. That’s it!

Note: If you are using a non-admin account, you’ll be asked to enter the admin account password in order to open the Command Prompt as administrator.

Method 2 of 6

Use search to open elevated Prompt from Start

Step 1: Open Start by either clicking the Windows logo key on the bottom left corner of the screen or by pressing the Windows logo key on the keyboard.

Step 2: Type Command Prompt or CMD in the search box to see Command Prompt entry in the result, right-click on the Command Prompt, and then click Run as administrator.

Method 3 of 6

Download File From Command Line Windows

File

Admin Command Prompt from Start menu

Download File Command Line Windows 10

Step 1: Open the Start by clicking the Windows logo button on the extreme left on the taskbar (bottom left corner of the screen) or by pressing the Windows logo key on the keyboard.

Step 2: In the Start, click or tap All Apps, click or tap Windows System folder, right-click on Command Prompt and then click or tap Run as administrator.

Click or tap Yes button when you see the User Account Control box or enter the password of the admin account if you’re using the Admin account.

Method 4 of 6

CMD as administrator from File Explorer

Step 1: Open Run command dialog box by simultaneously pressing Windows logo and R keys.

Windows Download From Command Line

Step 2: In the Run command box, type %windir%System32 and then press Enter key to open System32 folder.

Step 3: Locate the file named cmd.exe, right-click on the same, and then click Run as administrator option.

Click Yes button or enter the admin account password when asked to do so.

Method 5 of 6

Open Command Prompt from Task Manager

This method is useful and works only if you signed into the admin account.

Step 1: Open Task Manager. To do so, you either right-click on Start button or taskbar and then click Task Manager. Task Manager can also be launched using Ctrl+ Shift+Esc hotkey.

If the Task Manager is launched with fewer details is launched, click More details to open the full version.

Step 2: Once the Task Manager is launched, click File menu.

Step 3: Now, hold down the Ctrl key and then click Run new task open Command Prompt as administrator. In this method, you’ll not see the User Account Control dialog box.

That’s it!

Method 6 of 6

Open Command Prompt window here as administrator

As you likely know, when we hold down the Shift key and right-click on a folder, Open Command Prompt window here option appears in the context menu. If you want to open the Command Prompt as administrator from a folder, you can use this method.

Step 1: Click File menu, hover the mouse cursor over Open Command Prompt to see Open Command Prompt as administrator option. Click on the same option to run Command Prompt as administrator.

That’s all we know. If there is an easier way to open Command Prompt as administrator, do let us know by leaving comments. You can also let us know if any of the above mentioned method is not working for you.

Tip: You can configure Windows to always open Command Prompt as administrator. Please go through our how to always run Command Prompt as administrator guide for detailed instructions.