Imthedude025

Download an website using CMD (Batch)

Apr 8th, 2018
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. title Download an website using CMD.
  3.  
  4. del /Q "%~dp0DScript.vbs"
  5. cls
  6.  
  7. echo Generating script..
  8. echo 'script by Salmon Trout: https://www.computerhope.com/forum/index.php?topic=110781.0 >> "%~dp0DScript.vbs"
  9. echo.>> "%~dp0DScript.vbs"
  10. echo myURL = wscript.arguments(0) >> "%~dp0DScript.vbs"
  11. echo myPath = wscript.arguments(1) >> "%~dp0DScript.vbs"
  12. echo Dim i, objFile, objFSO, objHTTP, strFile, strMsg >> "%~dp0DScript.vbs"
  13. echo Const ForReading = 1, ForWriting = 2, ForAppending = 8 >> "%~dp0DScript.vbs"
  14. echo Set objFSO = CreateObject( "Scripting.FileSystemObject" ) >> "%~dp0DScript.vbs"
  15. echo If objFSO.FolderExists( myPath ) Then >> "%~dp0DScript.vbs"
  16. echo strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) ) >> "%~dp0DScript.vbs"
  17. echo ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then >> "%~dp0DScript.vbs"
  18. echo strFile = myPath >> "%~dp0DScript.vbs"
  19. echo Else >> "%~dp0DScript.vbs"
  20. echo WScript.Echo "ERROR: Target folder not found." >> "%~dp0DScript.vbs"
  21. echo wscript.Quit >> "%~dp0DScript.vbs"
  22. echo End If >> "%~dp0DScript.vbs"
  23. echo Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True ) >> "%~dp0DScript.vbs"
  24. echo Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" ) >> "%~dp0DScript.vbs"
  25. echo.>> "%~dp0DScript.vbs"
  26. echo 'following line is optional >> "%~dp0DScript.vbs"
  27. echo wscript.echo "Downloading " ^& myURL >> "%~dp0DScript.vbs"
  28. echo.>> "%~dp0DScript.vbs"
  29. echo objHTTP.Open "GET", myURL, False >> "%~dp0DScript.vbs"
  30. echo objHTTP.Send >> "%~dp0DScript.vbs"
  31. echo For i = 1 To LenB( objHTTP.ResponseBody ) >> "%~dp0DScript.vbs"
  32. echo objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) ) >> "%~dp0DScript.vbs"
  33. echo Next >> "%~dp0DScript.vbs"
  34. echo objFile.Close( ) >> "%~dp0DScript.vbs"
  35. echo.>> "%~dp0DScript.vbs"
  36. echo 'following line is optional >> "%~dp0DScript.vbs"
  37. echo wscript.echo "Download complete" >> "%~dp0DScript.vbs"
  38. echo Generation complete!
  39. echo.
  40.  
  41. :: Input website bellow followed with output location.
  42. cscript //nologo "%~dp0DScript.vbs" "http://www.robgendlerastropics.com/primer.html" "C:\Users\%username%\Downloads"
  43. echo.
  44.  
  45. del /Q "%~dp0DScript.vbs"
  46.  
  47. echo Job finished!
  48. echo.
  49.  
  50. pause.
RAW Paste Data