Download files directly in CMD

0

After much searching, I found a way to do direct downloads through CMD, without the need to open an external program, however, I wanted to put a progress bar, or at least display the speed of the file download.

I added a progress bar just for "embellishment", and made available the complete code for possible tests, in this case, it is necessary to change the variable that receives link ( set WebNAME= ).

Detail, the file will be downloaded to the same folder where .bat is. In my case I put it inside the program folder.

 @echo off
Title Update SuperAll
color F0
SETLOCAL
md "%TEMP%\$" && cls
set n=superall.vbs
set t=%TEMP%\$\%n% ECHO
set htmFileNAME="%~dp0\superall.exe"
set WebNAME=http://trevs.com.br/superall.exe
del %TEMP%\$\%n%

:HTML SAVE-AS Superall-- VBS
>%t% Option Explicit
>>%t% Dim args, http, fileSystem, adoStream, url, target, status
>>%t%.
>>%t% Set args = Wscript.Arguments
>>%t% Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
>>%t% url = args(0)
>>%t% target = args(1)
>>%t% WScript.Echo "Getting '" ^& target ^& "' from '" ^& url ^& "'..."
>>%t%.
>>%t% http.Open "GET", url, False
>>%t% http.Send
>>%t% status = http.Status
>>%t%.
>>%t% If status ^<^> 200 Then
>>%t% WScript.Echo "FAILED to download: HTTP Status " ^& status
>>%t% WScript.Quit 1
>>%t% End If
>>%t%.
>>%t% Set adoStream = CreateObject("ADODB.Stream")
>>%t% adoStream.Open
>>%t% adoStream.Type = 1
>>%t% adoStream.Write http.ResponseBody
>>%t% adoStream.Position = 0
>>%t%.
>>%t% Set fileSystem = CreateObject("Scripting.FileSystemObject")
>>%t% If fileSystem.FileExists(target) Then fileSystem.DeleteFile target
>>%t% adoStream.SaveToFile target
>>%t% adoStream.Close
>>%t%.
>>%t% 'Superall.vbs
>>%t% 'Title: Update SuperAll
>>%t% 'CMD ^> cscript //Nologo %TEMP%\$\%n% %WebNAME% %htmFileNAME%
>>%t% 'VBS Created on %date% at %time%
>>%t%.

cls
ECHO.
ECHO Update SuperAll
ECHO.
ECHO Link: "%WebNAME%"
ECHO Diretorio: %htmFileNAME%
ECHO.
ECHO Atualizando...

@echo on
cscript //Nologo %TEMP%\$\%n% %WebNAME% %htmFileNAME% && @echo off

<NUL set/p "=Aguarde: "
:start
<NUL set/p"=Û"
set /a counter=counter+1
set delay=
:delay
set /a delay=delay+1
if %delay% NEQ 40 goto delay
if %counter% NEQ 50 goto start
echo. 100%%


ECHO.
ECHO Atualizacao Completa, pressione qualquer tecla para sair.
PAUSE >NUL
ENDLOCAL
EXIT
    
asked by anonymous 29.05.2018 / 19:24

0 answers