Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
986 views
in Technique[技术] by (71.8m points)

windows - VBS/Batch Check if Download Complete

Is there any way using VBS with its default options (without WGet, PowerShell, etc.) to check if a downloaded file is completely 100% downloaded?

The script I'm using successfully downloads files, but I don't know how to check if the file is 100% downloaded and haven't been able to find a way to do this with default Windows (7/8) features (without having to enable custom features).

Alternately, if this is possible with Batch (or any other default Windows features for that matter) from within the VBS script, this would also be acceptable.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is a mixed script [Batch/Vbscript] to download a file from a URL typed by the user from inputBox.

@echo off
mode con:cols=70 lines=8 & Color 9B
Title -==*==- Batch Downloader file by Hackoo -==*==-
(
echo Option Explicit
echo.
echo Dim Message, result
echo Dim Title, Text1, Text2
echo.
echo Message = "Type the URL of the file to download."        
echo Title = "Download a file from URL by Hackoo"
echo Text1 = "You canceled"
echo.
echo result = InputBox^(Message, Title, "http://www.gametop.com/online-free-games/anti-terror-force-online/game.swf", 900, 900^)
echo.
echo.
echo If result = "" Then
echo    WScript.Echo Text1
echo Else
echo    WScript.Echo result
echo End If
)>"%tmp%inputbox.vbs"
for /f "tokens=* delims=*" %%a in ('Cscript "%tmp%inputbox.vbs" //nologo') do (set "a=%%a")
(
echo path = "%A%"
echo pos = InStrRev(path, "/"^) +1
echo Const DownloadDest = "%A%"
echo LocalFile = Mid(path, pos^)
echo Const webUser = "admin"
echo Const webPass = "admin"
echo Const DownloadType = "binary"
echo dim strURL
echo.
echo function getit(^)
echo  dim xmlhttp
echo.
echo  set xmlhttp=createobject("MSXML2.XMLHTTP.3.0"^)
echo  'xmlhttp.SetOption 2, 13056 'If https -^) Ignorer toutes les erreurs SSL
echo  strURL = DownloadDest
echo  Wscript.Echo "Download-URL: " ^& strURL
echo.
echo  'Pour l'authentification de base, utilisez la liste ci-dessous, ainsi que les variables + d'utilisateurs? laisser passer
echo  'xmlhttp.Open "GET", strURL, false, WebUser, WebPass
echo  xmlhttp.Open "GET", strURL, false
echo.
echo  xmlhttp.Send
echo  Wscript.Echo "Download-Status: " ^& xmlhttp.Status ^& " " ^& xmlhttp.statusText
echo.
echo  If xmlhttp.Status = 200 Then
echo    Dim objStream
echo    set objStream = CreateObject("ADODB.Stream"^)
echo    objStream.Type = 1 'adTypeBinary
echo    objStream.Open
echo    objStream.Write xmlhttp.responseBody
echo    objStream.SaveToFile LocalFile,2
echo    objStream.Close
echo    set objStream = Nothing
echo  End If
echo.
echo.
echo  set xmlhttp=Nothing
echo End function
echo.
echo '=======================================================================
echo ' Fin Defs de fonction, Start Page
echo '=======================================================================
echo getit(^)
echo Wscript.Echo "Download Completed. Check " ^& LocalFile ^& " for success."
echo Wscript.Quit(intOK^)
)>"%tmp%httpdownload.vbs"
::Debut
echo Please wait ... The downloading file is in progress ...
echo.
for /f "tokens=* delims=*" %%a in ('Cscript "%tmp%httpdownload.vbs" //nologo') do (echo "%%a")
Del %tmp%httpdownload.vbs
::fin
pause>nul

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...