Reputation: 730
I am having problems with downloading files from the internet using a Batch script. I found the following pieces of code - though none of them seem to work
xcopy /E /Y "https://website.com/file.bat"
wget.exe --no-check-certificate https://website.com/file.bat
I am trying to make my batch automatically fetch a file, but I am pretty clueless on how to.
I am open to (explained very simple) vbscripts too. Thanks in advance!
Upvotes: 0
Views: 2180
Reputation: 18827
This an example to download a game.swf
Try and get inspired by it :
@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
Upvotes: 2
Reputation: 113
If you have PowerShell >= 3.0, you can use Invoke-WebRequest
Invoke-WebRequest -OutFile file.bat https://website.com/file.bat
Or
wget -outf file.bat --no-check-certificate https://website.com/file.bat
Upvotes: 0