从批量网站下载文件 [英] download a file from a website with batch
问题描述
我试图创建一个自动化脚本来安装和更新窗口矿工艺编辑MCEDIT。这里是我迄今为止
关闭@echoREM找到Windows安装的结构。
章查询HKLM \\五金\\说明\\ SYSTEM \\ CentralProcessor \\ 0|发现/我的x86> NUL&功放;&安培;设置弧= || 32BIT集弧= 64BIT如果弧%==%32BIT GOTO 32
如果弧%==%64BIT GOTO 64REM占位符进行测试。
集版本= 1.5.3.0
:32
REM attepts使用的bitsadmin下载文件,但失败。
bitsadmin.exe /转移作业名 https://github.com/Khroki/MCEdit-Unified/releases/download/^%version%/MCEdit.^%version%.Win.32bit.exe \\ INSTALL.EXE
:64
REM在的bitsadmin另一种尝试也失败
bitsadmin.exe /转移测试/下载https://github.com/Khroki/MCEdit-Unified/releases/download/^%version%/MCEdit.^%version%.Win.64bit.exe \\ INSTALL.EXEREM解压自动提取到当前位置
INSTALL.EXE / S / D%CD%
:结束
回声结束
暂停
所以我遇到的第一个问题是。
bitsadmin.exe /转移作业名 https://github.com/Khroki/MCEdit-Unified/releases/download/^%version%/MCEdit.^%version%.Win.32bit.exe \\ INSTALL.EXE
总是失败,也就是德preciated并很快从Windows entirly被丢弃。我期待的,不会要求用户在additon东西下载到这个脚本来完成任务的本地解决方案。
我遇到的第二个问题是,我有没有办法获得最新的版本。文件总是存储在
<$p$p><$c$c>https://github.com/Khroki/MCEdit-Unified/releases/download/(version_number)/mcedit.(version_number).exe所以,我需要一种方法来测试服务器或方法来打印包含目录的文本文件的最新版本,并做本地。
请确认您的网址是否正确;所以这是用一个例子的bitsadmin
和它的作品5/5对我来说:
关闭@echo
:menuLOOP
CLS
标题下载清洁工具由Hackoo 2016年中删除病毒
颜色9E&安培;模式CON COLS = 80行= 11
回声(
回声(
回声(****菜单****************** ************
回声(
FOR / F令牌= 2 * delims = _%% A有('FINDSTR / B / C:menu_%〜F0')做(
呼应%%一个%% B)
回声(
回声(************ *****************
组选=
回声(安培;设置/ p =选择做一个选择,或按ENTER键退出:|| GOTO:EOF
回声(安培;拨打:菜单_ [%选择%]
GOTO:menuLOOP
:: ************ ***********
:menu_ [1]下载并RogueKiller删除工具扫描
CLS
模式CON COLS = 100行= 5和颜色9E
回声(
设置URL = HTTP://www.sur-la-toile.com/RogueKiller/RogueKiller.exe
设置位置=%USERPROFILE%\\桌面\\ RogueKiller.exe
标题下载RogueKiller病毒清除工具...
呼叫:下载%URL%%位置%
启动%位置%
转到:MenuLoop
:: ************ ************
:menu_ [2]下载,并与McAfee毒刺扫描工具扫描
CLS
模式CON COLS = 100行= 5和颜色9E
回声(
设置URL32 = HTTP://downloadcenter.mcafee.com/products/mcafee-avert/stinger/stinger32.exe
设置URL64 = HTTP://downloadcenter.mcafee.com/products/mcafee-avert/stinger/stinger64.exe
设置位置=%USERPROFILE%\\桌面\\ stinger32.exe
设置RegQry = HKLM \\五金\\说明\\ SYSTEM \\ CentralProcessor \\ 0
REG查询%RegQry%GT; checkOS.txt
查找/ I86&LT; CheckOS.txt&GT; StringCheck.txt
如果%ERRORLEVEL%EQU 0(
回声:这是32位操作系统
暂停
标题下载迈克菲毒刺扫描工具...
呼叫:下载%URL32%%位置%
德尔checkOS.txt&安培;德尔StringCheck.txt
)ELSE(
设置位置=%USERPROFILE%\\桌面\\ stinger64.exe
标题下载迈克菲毒刺扫描工具...
回声:这是64位操作系统
暂停
呼叫:下载%URL64%%位置%
德尔checkOS.txt&安培;德尔StringCheck.txt
)
转到:MenuLoop
:: ************ **************
:下载&LT; URL&GT; &LT;地点&gt;
设置URL =%〜1
设置位置=%〜2
如果存在%〜2删除%〜2
的bitsadmin /传送下载%〜1%〜2
如果存在%〜2开始%〜2
如果%ERRORLEVEL%GTR 0(
呼叫:PSDownload%〜1%〜2
)
转到:MenuLoop
:: ************ **************
在PowerShell中REM功能的下载文件
:PSDownload&LT; URL&GT; &LT;文件&gt;
设置psfile中=%TMP%\\ PSFile.ps1
(
回声$向下=新对象System.Net.WebClient;
回声$ URL =%〜1;
回声$文件=%〜2;
回声$ down.DownloadFile($网址,$ ^文件);
回声$ EXEC =新对象-com shell.application;
回声$ exec.shellexecute($文件^);
)&GT;%psfile中%
如果存在%〜2删除%〜2
呼叫:讲请稍候...正在下载文件%〜2正在进行中......
Powershell.exe -ExecutionPolicy旁路-file%psfile中%
如果存在%〜2开始%〜2
德尔%psfile中%
转到:MenuLoop
:: ************ ***************
i am attempting to create an automation script to install and update the mine craft editor MCEDIT on windows. here is what i have so far
@echo off
REM finds the architecture of the windows installation.
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set arc=32BIT || set arc=64BIT
if %arc%==32BIT GOTO 32
if %arc%==64BIT GOTO 64
REM placeholder for testing.
set version=1.5.3.0
:32
REM attepts to use bitsadmin to download file but fails.
bitsadmin.exe /transfer "JobName" https://github.com/Khroki/MCEdit-Unified/releases/download/^%version%/MCEdit.^%version%.Win.32bit.exe .\install.exe
:64
REM another attempt at bitsadmin that also fails
bitsadmin.exe /transfer "test" /download https://github.com/Khroki/MCEdit-Unified/releases/download/^%version%/MCEdit.^%version%.Win.64bit.exe .\install.exe
REM unzips the auto extractor to current location
install.exe /s /d %cd%
:end
echo end
pause
so the first issue i am having is that.
bitsadmin.exe /transfer "JobName" https://github.com/Khroki/MCEdit-Unified/releases/download/^%version%/MCEdit.^%version%.Win.32bit.exe .\install.exe
always fails, it is also depreciated and soon to be dropped from windows entirly. i am looking for a native solution that would not require a user to download anything in additon to this script to complete the task.
The second issue i am having is that i have no way to get the current version. the files are always stored at
https://github.com/Khroki/MCEdit-Unified/releases/download/(version_number)/mcedit.(version_number).exe
So i need a way to test for the newest version on the server or a way to print a text file containing the directories and do it locally.
Check if your URL is correct or not; so this an example that use Bitsadmin
and it works 5/5 for me :
@echo off
:menuLOOP
cls
Title Downloading Cleaning Tools to remove virus by Hackoo 2016
Color 9E & Mode con cols=80 lines=11
echo(
echo(
echo( ***************************** Menu ******************************
echo(
for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do (
echo %%A %%B )
echo(
echo( *****************************************************************
set choice=
echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
echo( & call :menu_[%choice%]
GOTO:menuLOOP
::***********************************************************
:menu_[1] Download and Scan with RogueKiller Removal Tool
Cls
Mode con cols=100 lines=5 & color 9E
echo(
Set "URL=http://www.sur-la-toile.com/RogueKiller/RogueKiller.exe"
Set "Location=%userprofile%\Desktop\RogueKiller.exe
Title Downloading RogueKiller Virus Removal Tool ...
Call :Download "%URL%" "%Location%"
Start "" "%Location%"
Goto:MenuLoop
::************************************************************
:menu_[2] Download and Scan with McAfee Stinger Scanner Tool
Cls
Mode con cols=100 lines=5 & color 9E
echo(
Set "URL32=http://downloadcenter.mcafee.com/products/mcafee-avert/stinger/stinger32.exe"
Set "URL64=http://downloadcenter.mcafee.com/products/mcafee-avert/stinger/stinger64.exe"
Set "Location=%userprofile%\Desktop\stinger32.exe
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG Query %RegQry% > checkOS.txt
Find /i "x86" < CheckOS.txt > StringCheck.txt
If %ErrorLevel% EQU 0 (
Echo "This is 32 Bit Operating system"
pause
Title Downloading McAfee Stinger Scanner Tool ...
Call :Download "%URL32%" "%Location%"
Del checkOS.txt & del StringCheck.txt
) ELSE (
Set "Location=%userprofile%\Desktop\stinger64.exe
Title Downloading McAfee Stinger Scanner Tool ...
Echo "This is 64 Bit Operating System"
pause
Call :Download "%URL64%" "%Location%"
Del checkOS.txt & del StringCheck.txt
)
Goto:MenuLoop
::**************************************************************
:Download <URL> <Location>
Set URL="%~1"
Set Location="%~2"
If Exist "%~2" Del "%~2"
Bitsadmin /transfer "Download" "%~1" "%~2"
If Exist "%~2" Start "" "%~2"
If %ErrorLevel% GTR 0 (
Call :PSDownload "%~1" "%~2"
)
Goto:MenuLoop
::**************************************************************
Rem Function in Powershell for Downloading file
:PSDownload <url> <file>
Set PSFile=%Tmp%\PSFile.ps1
(
echo $down = New-Object System.Net.WebClient;
echo $url = "%~1";
echo $file = "%~2";
echo $down.DownloadFile($url,$file^);
echo $exec = New-Object -com shell.application;
echo $exec.shellexecute($file^);
)>%PSFile%
If Exist "%~2" Del "%~2"
Call :Speak "Please Wait... Downloading file "%~2" is in Progress..."
Powershell.exe -ExecutionPolicy bypass -file %PSFile%
If Exist "%~2" Start "" "%~2"
Del %PSFile%
Goto:MenuLoop
::***************************************************************
这篇关于从批量网站下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!