Visual script to Download a file from internet.
There are so many ways to Download file from internet, there may be scenario arise when you will need files to be downloaded by command.
You need to follow below steps to download file from internet through command.
1. Create a file in local drive with below content, you should give file url in strFileURL variable.
' give complete url of file and local location of file where we are storing the file
strFileURL = "https://server_name/exact_file_url"
strHDLocation = "one.avi"
' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
Set objFSO = Nothing
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if
Set objXMLHTTP = Nothing
2. and run the below command.
'VScript file_name.vbs
No comments:
Post a Comment