簡體   English   中英

從網站批量下載文件

[英]download a file from a website with batch

我正在嘗試創建一個自動化腳本來在 Windows 上安裝和更新 minecraft 編輯器 MCEDIT。 這是我到目前為止所擁有的

@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

所以我遇到的第一個問題是。

bitsadmin.exe /transfer "JobName" https://github.com/Khroki/MCEdit-Unified/releases/download/^%version%/MCEdit.^%version%.Win.32bit.exe .\install.exe

總是失敗,它也會貶值,很快就會完全從窗戶上掉下來。 我正在尋找一種本機解決方案,它不需要用戶下載除此腳本之外的任何內容即可完成任務。

我遇到的第二個問題是我無法獲得當前版本。 文件總是存儲在

https://github.com/Khroki/MCEdit-Unified/releases/download/(version_number)/mcedit.(version_number).exe

所以我需要一種方法來測試服務器上的最新版本,或者一種方法來打印包含目錄的文本文件並在本地進行。

檢查您的網址是否正確; 所以這是一個使用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