Here is the function to download any file over internet using XMLHTTP COM objects in VBScript.
I got this script from internet and thanks for the author as I forgot where I took this.
- Function Download(sFileURL, sLocation)
- 'create xmlhttp object
- Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
- 'get the remote file
- objXMLHTTP.open "GET", sFileURL, false
- 'send the request
- objXMLHTTP.send()
- 'wait until the data has downloaded successfully
- do until objXMLHTTP.Status = 200 : wscript.sleep(1000) : loop
- 'if the data has downloaded sucessfully
- If objXMLHTTP.Status = 200 Then
- 'create binary stream object
- Set objADOStream = CreateObject("ADODB.Stream")
- objADOStream.Open
- 'adTypeBinary
- objADOStream.Type = 1
- objADOStream.Write objXMLHTTP.ResponseBody
- 'Set the stream position to the start
- objADOStream.Position = 0
- 'create file system object to allow the script to check for an existing file
- Set objFSO = Createobject("Scripting.FileSystemObject")
- 'check if the file exists, if it exists then delete it
- If objFSO.Fileexists(sLocation) Then objFSO.DeleteFile sLocation
- 'destroy file system object
- Set objFSO = Nothing
- 'save the ado stream to a file
- objADOStream.SaveToFile sLocation
- 'close the ado stream
- objADOStream.Close
- 'destroy the ado stream object
- Set objADOStream = Nothing
- 'end object downloaded successfully
- End if
- 'destroy xml http object
- Set objXMLHTTP = Nothing
- End Function
- 'Call like this
- Download "http://tamilmp3world.com/123.mp3", "C:\test1.mp3"
I got this script from internet and thanks for the author as I forgot where I took this.
Comments
Post a Comment