'为每天建立一个目录
dim fso,fd,f
set fso=createobject("scripting.filesystemobject")
foldername=fso.GetFolder(".").Path&"\"&Date()
'先判定文件夹是否存在
adosCacheSize=100*1024*1024'设为100M,
BlockSize=50*1024*1024'此处表示50M
If Not fso.FolderExists(foldername) Then
fso.CreateFolder foldername
End if
for i=0 to 9 '从0-9循环。服务器上备份的文件为linkhelperdata.zip.001 linkhelperdata.zip.002等。为0的情况,是如果没有分包的话。9个,总共有9*800M=7.2G的文件大小。应该足够。
If i=0 Then
filename="linkhelperdata.zip"
Else
filename="linkhelperdata.zip.00"&i
End If
downurl="http://www.linkhelper.cn/"&filename
If fso.FileExists(foldername&"\"&filename) Then'判断要下载的文件是否已经存在
RangeStart=fso.GetFile(foldername&"\"&filename).Size'若存在,以当前文件大小作为开始位置
Else
RangeStart=0'若不存在,一切从零开始
'fso.CreateTextFile(foldername&"\"&filename).Close'新建文件
End If
FileDownStart=RangeStart
'msgbox lenb(RangeStart)
Set ados = CreateObject("Adodb.Stream")
Set adosCache=CreateObject("Adodb.Stream")
adosCache.Type=1
adosCache.Mode=3
adosCache.Open
Do
BlockStartTime=Timer()
Set xPost =createObject("Microsoft.XMLHTTP")
xPost.Open "GET",downurl,0 ''''下载文件的地址
xPost.setRequestHeader "Accept","*/*"
xPost.setRequestHeader "Range","bytes="&RangeStart&"-"&Cstr(RangeStart+BlockSize-1)'
'MsgBox "bytes="&RangeStart&"-"&Cstr(RangeStart+BlockSize-1)
xPost.setRequestHeader "Content-Type","application/octet-stream"
xPost.setRequestHeader "Pragma","no-cache"
xPost.setRequestHeader "Cache-Control","no-cache"
xPost.Send()
'MsgBox xPost.status
If xPost.status=404 Then
Exit Do
If i>0 then
exit For
End if
End if
If xPost.status = 416 Then'
Exit Do
End If
If RangeStart=0 Then
fso.CreateTextFile(foldername&"\"&filename).Close'新建文件
End if
If adosCache.Size >= adosCacheSize Then
ados.type=1
ados.mode=3
ados.open
ados.LoadFromFile foldername&"\"&filename
ados.position=ados.size
adosCache.Position = 0
'msgbox ados.size
'response.write "adosCache.size:"&adosCache.size&"<br>"
'response.write "ados.size:"&ados.size&"<br>"
'response.flush
'response.end
ados.Write adosCache.Read
ados.SaveToFile foldername&"\"&filename,2
ados.close
adosCache.Position=0
adosCache.SetEOS
End If
'MsgBox lenb(xPost.responseBody)
'On Error Resume next
'response.write "adosCache.size:"&adosCache.size&"<br>"
'response.write "xPost.responseBody:"&Lenb(xPost.responseBody)&"<br>"
'response.flush
adosCache.Write xPost.responseBody'
'If Err.number<>0 Then
' Err.clear
' response.write "adosCache.size:"&adosCache.size&"<br>"
' response.write "xPost.responseBody:"&Len(xPost.responseBody)&"<br>"
' response.write Err.description
' response.end
'End if
ResponseRange=xPost.getResponseHeader("Content-Range")
'MsgBox xPost.getAllResponseHeaders()
temp=Mid(ResponseRange,Instr(ResponseRange,"-")+1)
CurrentLastBytes=cdbl(Left(temp,Instr(temp,"/")-1))
TotalBytes = cdbl(Mid(temp,Instr(temp,"/")+1))
'MsgBox CurrentLastBytes
'MsgBox TotalBytes
If TotalBytes - CurrentLastBytes = 1 Then
FileDownEnd=TotalBytes
ados.Type=1'
ados.Mode=3'
ados.Open
ados.LoadFromFile foldername&"\"&filename
ados.position=ados.size
adosCache.Position = 0
ados.Write adosCache.Read
ados.SaveToFile foldername&"\"&filename,2
ados.close
Exit do
End If
RangeStart=RangeStart+BlockSize
loop
adosCache.close
Set adosCache=Nothing
Set ados=nothing
set xPost=nothing
next
'删除history