简体   繁体   English

从网站批量下载文件

[英]download a file from a website with batch

i am attempting to create an automation script to install and update the mine craft editor MCEDIT on windows.我正在尝试创建一个自动化脚本来在 Windows 上安装和更新 minecraft 编辑器 MCEDIT。 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 :所以这是一个使用Bitsadmin的例子, Bitsadmin我来说是 5/5:

@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
::***************************************************************

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM