I want a way to download a file via HTTP given its URL (similar to how wget works). I've seen the answers to this question, but I have two changes to the requirements:

  • I'd like it to run on Windows 7 or later (though if it works on Windows XP, that's a bonus).
  • I need to be able to do this on a stock machine with nothing but the script, which should be text that could be easily entered on a keyboard or copy/pasted.
  • The shorter, the better.

So, essentially, I'd like a .cmd (batch) script, VBScript, or Powershell script that can accomplish the download. It could use COM or invoke IE, but it needs to run without any input, and should behave well when invoked without a display (such as through a telnet session).

link|improve this question

feedback

2 Answers

up vote 5 down vote accepted

Try the Web Client 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()
link|improve this answer
This is helpful. I found the WebClient also has a DownloadFile method, which will download the content directly to a file. Thanks. – Jason R. Coombs Apr 10 '10 at 11:56
feedback

i would use 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 windows7 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, see here for an example vbscript. and there is 'bitsadmin', a commandline 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 windows7 bitsadmin.exe states itself that it is a deprecated tool. nevertheless:

% bitsadmin.exe /transfer "NAME" http://path/to/file C:\Path\for\local\file
link|improve this answer
1  
It appears now that bitsadmin is deprecated and may not be included in future versions of Windows. – Jason R. Coombs Feb 20 at 14:11
@JasonR.Coombs: link? reference? – akira Feb 21 at 6:06
1  
technet.microsoft.com/en-us/magazine/ff382721.aspx ... so, instead of "bitadmin.exe" one just uses bits-cmdlets. – akira Feb 21 at 6:24
thanks for that. All I had to go on was bitsadmin was telling me it was deprecated when I ran it. – Jason R. Coombs Feb 22 at 12:27
feedback

Your Answer

 
or
required, but never shown

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