Download a file using command line in Windows

If you want to download a file using only command line, you can create a batch file (.bat) with the following :


@Echo OFF
SetLocal EnableDelayedExpansion
powershell.exe -Command (new-object System.Net.WebClient).DownloadFile('', 'C:\destination\test.txt')

Of course you have to change the source and destination according to your needs.

The only problem is that running this file will open the command prompt for few seconds .. to avoid that you can create a VBscript file (.vbs) that will run the batch file in the background without the appearance of the command prompt.


Set oShell = CreateObject ("Wscript.Shell") 
Dim strArgs
strArgs = "cmd /c download.bat"
oShell.Run strArgs, 0, false

Leave a Reply

Your email address will not be published. Required fields are marked *