如何在不使用任何外部工具的情况下下载带有批处理文件的文件? [英] How can I download a file with batch file without using any external tools?

查看:29
本文介绍了如何在不使用任何外部工具的情况下下载带有批处理文件的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先要澄清这个问题是针对 HTTP(s) 下载.对于 FTP,我会问(并回答)另一个问题.这里有一些类似的问题 - 但我想要更多精确.

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 .

除了排除外部工具之外,我希望解决方案适用于尽可能广泛的 Windows 机器类型(包括 XP、Win2003、Vista,它们仍然具有足够大的份额).此外,由于 WSH 是可能的选项之一,我更喜欢不使用临时文件并将所有内容打包在单个 .bat 文件中(jscript 和 vbscript 都可以)).

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).

有哪些可能的方法.

  1. 带有 BITSADMIN 的纯"批处理解决方案 - 一个命令行实用程序在每台 Windows 机器上都可用.它不是很方便,但它是唯一的选择不应使用其他脚本语言.
  2. 使用 WSH - 可以使用三种方法 - WinHTTP , MSXML2.XMLHTTP,InternetExlorer.Application - 所有这些可访问 ActiveX对象按我喜欢的顺序排列.WinHTTP 和 MSXML2.XMLHTTP它们的功能非常相似,但 WinHTTP 具有口碑比较稳定.InternetExlorer.Application其实是只是通过 ActiveX 对象访问的 Internet Explorer 和一些 UI 元素是不可避免的(是吗?)所以我会跳过这个.
  3. 使用 .NET - 可以创建包含所有内容的混合批处理文件三个默认的 .NET 编译器(Jscript.net、VB.Net、C#)与Jscript.net 没有多余的错误消息,所以我更喜欢它.如果我们忽略了一个事实,即有一个编译的 .exe 的所有代码在一个文件中,所以据我说这符合要求:-).使用 .NET 我们可以使用 System.Net.WebClient 或System.Net.HttpWebRequest(WebClient 依赖于它)或
    System.Web.HttpRequest ,但现在我只会发布System.Net.WebClient 解决方案.甚至更多相同的 ActiveX 对象可以使用 WSH 访问这里也可用.所以真的有很多使用 .Net 加载文件的方法.将来我会更新我的回答.无论如何,只有 Web 客户端是专门为下载而设计的.
  4. 使用 powershell - 与 .NET 具有相同的可能性,但更少有机会安装在你能遇到的所有机器上.所以我会跳过这个也是.
  1. "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.
  2. 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.
  3. 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.
  4. 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.

推荐答案

答案.所有脚本都应该使用 .bat/.cmd 扩展名保存,并且可以使用直接作为批处理脚本.

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

  1. 证书(由于某些原因,在最新的 win10 版本中,这被认为是木马线程):

  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

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 命令可被滥用以从互联网下载文件.Windows 中默认可用从 Vista 开始.对于 WinXP Server 2003 需要管理工具.

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:

最简单的使用方法

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

使用宏:

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

或使用 bitsDownloader.bat

call bitsDownloader.bat "https://download.sysinternals.com/files/PSTools.zip" pstools.zip

  1. winhhtpjs.bat 是一个命令行 http 客户端,它使用 WinHttpRequest .它可以执行整个范围的 http (POST,DELETE,..) 请求,也可以用于下载文件(不是太大的文件).还可以添加自定义标头.
  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 是使用 MSXML2.XMLHTTP 对象下载文件.不提供像 winhhtpjs.bat ,但仍然是一个选项.

  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.

调用 XMLHTTPDownloadJS.bathttps://download.sysinternals.com/files/PSTools.zip pst2.zip";pstools.zip

call XMLHTTPDownloadJS.bat "https://download.sysinternals.com/files/PSTools.zip pst2.zip" pstools.zip

  • WebClientDownload.bat 使用 .NET System.Net.WebClient 类.它会创建一个小的 exe 文件以进行自我编译,并且需要安装一个 .net 框架.由于该类出现在 .net 的早期版本中,因此它具有足够的向后兼容性

  • 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. 在最新版本的 Windows 10 中,我们有 CURL 命令,尽管这不是向后兼容的选项.请注意,只有最新版本的 Windows 才会默认安装 CURL.

    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"--输出pstools.zip

    curl "https://download.sysinternals.com/files/PSTools.zip" --output pstools.zip

  • 这篇关于如何在不使用任何外部工具的情况下下载带有批处理文件的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆