How can I download a file with batch file without using any external tools?

The answers.All scripts should be saved with .bat/.cmd extensions and can be used directly as batch scripts.

  1. Certutuil (for some reasons in the newest win10 builds this is recognized as trojan thread ):certutil.exe -urlcache -split -f “https://download.sysinternals.com/files/PSTools.zip” pstools.zip

for easiness a macro can be used:

set "download=certutil.exe -urlcache -split -f"
%download% "https://download.sysinternals.com/files/PSTools.zip" pstools.zip

CertUtil command can be abused to download a file from internet.Available by default in windows since Vista.For WinXP Server 2003 Administration Tools are needed.

  1. Bitsadmin :

simplest possible way to use it

bitsadmin /transfer myDownloadJob /download /priority normal http://downloadsrv/10mb.zip c:\10mb.zip

with macro:

set "dnld=bitsadmin /transfer myDownloadJob /download /priority normal"
%dnld% "https://download.sysinternals.com/files/PSTools.zip" %cd%\pstools.zip

or with bitsDownloader.bat

call bitsDownloader.bat "https://download.sysinternals.com/files/PSTools.zip" pstools.zip
  1. winhhtpjs.bat is a command line http client that uses WinHttpRequest .It can perform whole range of http (POST,DELETE,..) requests and can be used for downloading of files too (not too big files).Also custom headers can be added.
call winhhtpjs.bat "https://example.com/files/some.zip" -saveTo "c:\somezip.zip" 
  1. XMLHTTPDownloadJS.bat is bat file that uses MSXML2.XMLHTTP object to download a file . Does not offer so rich options as winhhtpjs.bat , though is still an option.call XMLHTTPDownloadJS.bat “https://download.sysinternals.com/files/PSTools.zip pst2.zip” pstools.zip
  2. WebClientDownload.bat uses the .NET System.Net.WebClient class. It creates a small exe file in order to selfcompile itself and requires an installed a .net framework. As the class is presented in the very earlier versions of .net it is backward compatible enough
call webclientDownload.bat "https://download.sysinternals.com/files/PSTools.zip" pstools.zip
  1. With the latest builds of windows 10 we have the CURL command ,though this is not so backward compatible option. Mind that only the newest versions of windows has CURL installed by default.curl “https://download.sysinternals.com/files/PSTools.zip” –output pstools.zip

Leave a Comment