First to clarify this question is aimed to HTTP(s) download .For FTP may be I'll ask (and answer) another question. Here are some similar questions - but I want to be more precise .
Besides excluding external tools I want the solution(s) to be applicable for the widest possible types of windows machines (including XP,Win2003,Vista which still have big enough share).
Also as WSH
is one of the possible options I prefer no using of temp files and everything to be packed in a single .bat
file (which is possible with both jscript and vbscript).
What are possible approaches.
- "Pure" batch solution with BITSADMIN - a command line utility available on every windows machine .It's not pretty convenient but is an/the only option where no other scripting language should be used.
- Using WSH - Three approaches are possible - WinHTTP , MSXML2.XMLHTTP ,InternetExlorer.Application - all of them are accessible ActiveX objects in order of how I prefer them.WinHTTP and MSXML2.XMLHTTP are pretty similar in their capabilities but WinHTTP has a reputation of more stable.InternetExlorer.Application is in fact just the Internet explorer accessible through ActiveX object and some UI elements are unavoidable (are they?) so I'll skip this one.
- Using .NET - It's possible to create a hybrid batch file with all
the three default .NET compilers (Jscript.net , VB.Net , C#) with
Jscript.net there is no redundant error messages so I'll prefer
it.If we ignore the fact that there's a compiled .exe all the code
is in one file ,so according to me this fits in the requirements :-)
.With .NET we can use System.Net.WebClient or
System.Net.HttpWebRequest (the WebClient relies on it) or
System.Web.HttpRequest , but for now I'll post only System.Net.WebClient solution.And even more same ActiveX objects accessible with WSH are available here too.So there are really many ways to dowanload a file with .Net.May be in the future I'll update my answer.Anyway only the Webclient is especially designed for download. - Using powershell - has same possibilities as .NET but with less chances to be installed on all machines you can meet.So I'll skip this one too.
bitsadmin
be used to download every file on a webpage? – Ludovick