' Specify the directory to dowload files to: download_to="c:\" Set args=Wscript.Arguments Set tcpip=CreateObject("SHOTIP.Connection") ' You can uncomment the following line for registered version: 'tcpip.Timeout=180 tcpip.BinaryMode=True eol=Chr(13)&Chr(10) Main() Sub Main() Dim received,size received=0 size=1 While received"\" then targetpath=targetpath & "\" startstring="http://" if startstring<>Left(LCase(url),Len(startstring)) then Wscript.echo "Invalid URL" Exit Function end if turl=Mid(url,Len(startstring)+1) server=turl tmp=InStr(turl,"/") if tmp=0 then server=turl httpath="/" filename="default.htm" else server=Left(turl,tmp-1) httpath=Mid(turl,tmp) tmp1=InStrRev(httpath,"/") filename=Mid(httpath,tmp1+1) if filename="" then filename="default.htm" end if targetpath=Replace(targetpath & filename,"/","\") if not tcpip.Open(server,80) then Wscript.echo "Could not open connection to "&server Exit Function end if needrange=False if startsize<>0 then needrange=True httprequest = "GET " & httpath & " HTTP/1.0" & eol httprequest = httprequest & "Host: " & server & eol httprequest = httprequest & "User-agent: ShotIp ver1.2 (Win32)" & eol ' Placing Range header into request if needrange then httprequest = httprequest & "Range: bytes=" & startsize & "-" & (fullsize-1) & eol httprequest = httprequest & eol ' Sending HTTP request if not tcpip.Send(httprequest) then tcpip.Close() Wscript.echo "Could not send request" Exit Function end if Wscript.echo "Receiving data..." n=tcpip.Receive(data) if n=0 then Wscript.echo "Could not get server response" tcpip.Close() Exit Function end if ' Find the end of response header a=tcpip.FindInBinary(data,eol&eol,0,UBound(data)+1,1) if not IsArray(a) then tcpip.Close() Wscript.echo "Invalid response" Exit Function end if ' Parsing response header from first portion of data allhttp="" tcpip.WriteFile data,0,a(0),allhttp rlines=Split(allhttp,eol) pos1=InStr(rlines(0)," ") pos2=InStr(pos1+1,rlines(0)," ") code=Mid(rlines(0),pos1+1,pos2-pos1-1) code=code*1 Select Case code Case 200 if not needrange then Wscript.echo "Response Ok" else Wscript.echo "Server does not support range: trying to get full content" end if decsize=GetValue(rlines,"content-length")*1 fullsize=decsize Wscript.echo fullsize & " bytes should be received" Case 206 range=GetValue(rlines,"content-range") decsize=GetValue(rlines,"content-length")*1 pos2=InStr(range,"/") fullsize=Mid(range,pos2+1)*1 needappend=True Wscript.echo "Trying to get " & startsize & "-" & (fullsize-1) & " bytes..." Case 302 Wscript.echo "Document moved. New URL:" Wscript.echo GetValue(rlines,"location") tcpip.Close() Exit Function Case Else Wscript.echo "ERROR: " & Mid(rlines(0),pos1+1) Exit Function End Select Wscript.echo "Writing file: " & targetpath ' Writing the rest of first portion of data into file tcpip.WriteFile data,a(0)+4,UBound(data)-a(0)-3,targetpath,needappend sumsize=sumsize+UBound(data)-a(0)-3 While tcpip.Receive(data)>0 tcpip.WriteFile data,0,UBound(data)+1,targetpath,True sumsize=sumsize+UBound(data)+1 Wend tcpip.close() startsize=startsize+sumsize Wscript.echo "Received " & startsize & " bytes from " & fullsize if sumsize"" then GetValue=s Exit Function end if Next End Function Function GetValueFromStr(str,variable) Dim size,rfcvar GetValueFromStr="" rfcvar=variable & ": " size=Len(rfcvar) if StrComp(Left(str,size),rfcvar,1)=0 then GetValueFromStr=Mid(str,size+1) End Function