Download Files from Website

email me

I created these scripts to download files from a website. 

Script 1

Dim varHTTP, varBinaryString, varFileName, varLink

Set varHTTP = CreateObject("Microsoft.XMLHTTP")
Set varBinaryString = CreateObject("Adodb.Stream")

varFileName = "YourFileName.exe"
varLink = "http://YourUrl/" & varFileName
varHTTP.Open "GET", varLink, False
varHTTP.Send

With varBinaryString
.Type = 1 'my type has been set to binary
.Open
.Write varHTTP.responseBody
.SaveToFile ".\" & varFileName, 2 'if exist, overwrite
End With
varBinaryString.close

msgbox "Done!"

WScript.Quit(0)

 

Script 2

On error resume next
Dim PageStart, PagesToDownload, notebookpage
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

'STARTING PAGE TO DOWNLOAD
PageStart=1

'HOW MANY PAGES TO DOWNLOAD
PagesToDownload = 40

Do while PageStart < PagesToDownload
notebookpage = "<a href="http://eddiejackson.net/web_images/notebook_"><span style="text-decoration: underline;"><span style="color: #0000ff; font-size: medium;"><span style="color: #0000ff; font-size: medium;">http://eddiejackson.net/web_images/notebook_</span></span></span></a><span style="font-size: medium;">" & PageStart & ".jpg"
</span>If objFSO.FileExists (".\notebook_" & PageStart & ".jpg") then
'msgbox "FILE EXIST: notebook_" & PageStart & ".jpg"
PageStart=PageStart+1
Else
'msgbox "FILE DOES NOT EXIST: notebook_" & PageStart & ".jpg"
HTTPDownload notebookpage, "."
PageStart=PageStart+1
end if

loop

WScript.Quit(0)

Sub HTTPDownload( myURL, myPath )
'DEFINE MY VARIABLES
Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8

'CREATE OBJECT
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

' Check if the specified target file or folder exists,
' and build the fully qualified path of the target file
If objFSO.FolderExists( myPath ) Then
On error resume next
strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
strFile = myPath
Else
'WScript.Echo "ERROR: Target folder not found."
Exit Sub
End If

' Create or open the target file
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )

' Create an HTTP object
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

' Download the specified URL
objHTTP.Open "GET", myURL, False
objHTTP.Send

' Write the downloaded byte stream to the target file
For i = 1 To LenB( objHTTP.ResponseBody )
On error resume next
objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next

' Close the target file
objFile.Close( )

End Sub