Showing posts with label WGET. Show all posts
Showing posts with label WGET. Show all posts

Tuesday, January 31, 2017

How to download files from command line in Windows, like Wget

Create a file named 'Download_File.vbs' with following contents:


DownloadUrl = "http://ovh.net/files/10Mb.dat"
FileLocation = "Download.dat"

Wscript.Echo "Start Downloading"
Set ObjXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
ObjXMLHTTP.open "GET", DownloadUrl, false, "username", "password"
'http.setTimeouts 5000, 5000, 10000, 10000 'ms - resolve, connect, send, receive'
'http.setRequestHeader "Authorization", "Basic MY_AUTH_STRING"
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(FileLocation) Then ObjFSO.DeleteFile FileLocation
 Set ObjFSO = Nothing

 ObjADOStream.SaveToFile FileLocation
 ObjADOStream.Close
 Set ObjADOStream = Nothing
 Wscript.Echo "Download Completed: " + FileLocation
Else
 Wscript.Echo "File Not Found"
End if

Set ObjXMLHTTP = Nothing

And create another file in the same folder named 'Download_Command.bat' with following contents & double click to download file from defined url:


@ECHO OFF
cscript.exe Download_File.vbs
pause
exit;