Windows批处理用wget下载NirSoft工具出现文件损坏如何解决?
解决NirSoft工具批量下载损坏问题
问题根因
你拿到的4KB损坏文件实际是NirSoft服务器返回的反爬拦截/跳转页面,核心原因有两个:
- 原有链接替换逻辑错误:部分工具的zip包存放在
/toolsdownload/路径下,而非你替换的/utils/路径 - 下载工具未配置跟随跳转,请求头参数不符合服务器校验规则,且批处理中单引号包裹的参数不生效,导致你从cliget导出的命令无法正常运行
方案1:使用系统自带cURL(推荐,Win10 1809及以上版本无需额外安装)
批处理前置配置
脚本开头开启变量延迟:
@echo off setlocal enabledelayedexpansion :: 替换为你自己的时间戳变量生成逻辑 set Timestamp=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
修正链接替换逻辑
在原有fart替换步骤后,新增路径兼容处理,自动替换错误的存储路径:
:: 生成修正后的下载链接列表 del /q new-pad-links.txt 2>nul for /f "delims=" %%u in (pad-links.txt) do ( set "url=%%u" :: 先校验utils路径是否可访问 curl -o nul -s -w "%%{http_code}" "!url!" | findstr "200" >nul if !errorlevel! equ 0 ( echo !url! >> new-pad-links.txt ) else ( :: 不可访问则替换为toolsdownload路径 set "newurl=!url:/utils/=/toolsdownload/!" echo !newurl! >> new-pad-links.txt ) )
批量下载命令
for /f "delims=" %%u in (new-pad-links.txt) do ( curl -L ^ -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:115.0) Gecko/20100101 Firefox/115.0" ^ -H "Referer: https://www.nirsoft.net/" ^ -H "Accept: application/zip,*/*" ^ --connect-timeout 10 ^ --retry 3 ^ --output-dir "C:\Path\UtilSuit\NirLauncher\Download\" ^ -O "%%u" >> "C:\Path\Update\LOG\Nirsoft\%Timestamp%_NirSoft.log" 2>&1 )
方案2:使用wget修复
修正原有wget参数,注意批处理中所有参数需用双引号包裹,新增跟随跳转配置:
wget --timestamping ^ --input-file=C:\Path\UtilSuit\NirLauncher\Download\new-pad-links.txt ^ --append-output=C:\Path\Update\LOG\Nirsoft\%Timestamp%_NirSoft.log ^ --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:115.0) Gecko/20100101 Firefox/115.0" ^ --referer="https://www.nirsoft.net/" ^ --max-redirect=5 ^ --follow-redirects ^ --content-disposition
注意事项
- 不要使用早于2020年发布的wget/curl版本,旧版对TLS 1.2/1.3的支持存在缺陷,会导致HTTPS请求异常
- 所有带空格的路径、参数必须用双引号包裹,批处理不识别单引号作为参数包裹符
- 若仍出现小体积损坏文件,可将文件后缀改为
.html打开查看服务器返回的具体提示,针对性调整请求参数
内容的提问来源于stack exchange,提问作者dimarco76
相关产品推荐
相关产品推荐

