Download a file via HTTP from a script in Windows
If you have PowerShell >= 3.0, you can use Invoke-WebRequest
:
Invoke-WebRequest -OutFile su.htm -Uri superuser.com
Or golfed:
iwr -outf su.htm superuser.com
I would use Background Intelligent Transfer Service (BITS) (primer):
Background Intelligent Transfer Service (BITS) is a component of modern Microsoft Windows operating systems that facilitates prioritized, throttled, and asynchronous transfer of files between machines using idle network bandwidth.
Starting with Windows 7, Microsoft advises to use the PowerShell cmdlets for BITS.
% import-module bitstransfer
% Start-BitsTransfer http://path/to/file C:\Path\for\local\file
You could also use BITS via COM Objects, see here for an example VBScript. And there is bitsadmin
, a Command line tool to control downloads:
BITSAdmin is a command-line tool that you can use to create download or upload jobs and monitor their progress.
In Windows 7 bitsadmin.exe
states itself that it is a deprecated tool. Nevertheless:
% bitsadmin.exe /transfer "NAME" http://path/to/file C:\Path\for\local\file
Try the System.Net.WebClient
class. There is a sample PowerShell script at the bottom of this page:
$c = new-object system.net.WebClient
$r = new-object system.io.StreamReader $c.OpenRead("http://superuser.com")
echo $r.ReadToEnd()