How to Download Files via HTTP Using Native Windows Command Line Tools


2 views

While Windows Server 2008 doesn't include wget by default, it offers several built-in alternatives for HTTP file downloads:


:: Using bitsadmin (Background Intelligent Transfer Service)
bitsadmin /transfer mydownloadjob /download /priority normal http://example.com/file.zip C:\downloads\file.zip

:: Using certutil (Certificate Utility)
certutil -urlcache -split -f http://example.com/file.zip file.zip

Although not strictly "command line", PowerShell comes pre-installed and provides robust download capabilities:


# Basic download
(New-Object System.Net.WebClient).DownloadFile("http://example.com/file.zip", "C:\downloads\file.zip")

# With progress display
$wc = New-Object System.Net.WebClient
$wc.DownloadProgressChanged += {Write-Progress -Activity "Downloading" -Status "$($_.ProgressPercentage)%"}
$wc.DownloadFileAsync("http://example.com/file.zip", "C:\downloads\file.zip")

For environments where PowerShell isn't available, VBScript can be executed from command prompt:


' Save as download.vbs
Set x = CreateObject("MSXML2.XMLHTTP")
x.Open "GET", "http://example.com/file.zip", False
x.Send
Set s = CreateObject("ADODB.Stream")
s.Open
s.Type = 1
s.Write x.responseBody
s.SaveToFile "C:\downloads\file.zip", 2

For more complex scenarios requiring authentication or custom headers:


:: Using bitsadmin with credentials
bitsadmin /transfer myjob /download /priority normal http://example.com/protected.zip C:\secure.zip /setcredentials server user pass

:: PowerShell with headers
$headers = @{"Authorization"="Bearer token123"}
Invoke-WebRequest -Uri "http://api.example.com/data" -Headers $headers -OutFile "data.json"

Native tools support download resumption for large files:


:: Using bitsadmin to resume
bitsadmin /resume mydownloadjob

:: PowerShell alternative
$client = New-Object System.Net.WebClient
if (Test-Path "partial.file") {
    $client.DownloadFile("http://example.com/large.iso", "complete.iso")
}

Windows Server 2008 includes several native command-line tools that can handle HTTP file downloads without requiring third-party installations like wget or cURL. Here are the most practical approaches:

The most reliable built-in solution is bitsadmin.exe, which supports HTTP/HTTPS protocols:


REM Basic download example
bitsadmin /transfer mydownloadjob /download /priority normal http://example.com/file.zip C:\Downloads\file.zip

REM With authentication
bitsadmin /transfer securejob /download /priority high http://secured.com/data.xml C:\temp\data.xml /setcredentials server user password

While limited in PS1.0, you can perform basic downloads:


$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile("http://example.com/largefile.iso", "C:\temp\largefile.iso")

For environments with strict security policies, create a download.vbs file:


Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
Set objADOStream = CreateObject("ADODB.Stream")
objXMLHTTP.Open "GET", "http://example.com/package.exe", False
objXMLHTTP.Send()

If objXMLHTTP.Status = 200 Then
    objADOStream.Open
    objADOStream.Type = 1
    objADOStream.Write objXMLHTTP.responseBody
    objADOStream.Position = 0
    objADOStream.SaveToFile "C:\temp\package.exe"
    objADOStream.Close
End If

Large Files: Use bitsadmin with /priority high for better transfer management

Authentication Required: Both bitsadmin and the VBScript method support credentials

HTTPS Sites: All native methods support HTTPS, though may require proper certificate configuration

Tool HTTPS Resume Auth Server 2008
bitsadmin Yes Yes Yes Full support
PowerShell Yes No Yes Limited (v1.0)
VBScript Yes No Yes Full support

For production environments, I recommend bitsadmin for its resume capability and logging features. Create a batch wrapper for complex scenarios:


@echo off
set url=http://mirror.example.com/software/v2.3/installer.msi
set dest=C:\packages\installer.msi

bitsadmin /create download_package
bitsadmin /addfile download_package %url% %dest%
bitsadmin /setnotifycmdline download_package "%SystemRoot%\System32\cmd.exe" "/c echo Download complete >> C:\logs\download.log"
bitsadmin /resume download_package
bitsadmin /complete download_package