日期:2010-01-08 浏览次数:21230 次
<%
'文件名:updata.asp
'远程地址
const url="http://localhost/test/"
action=request("action")
if action="updata" then
download(url&"config.txt")
download(url&"pack.jpg")
response.Write("下载成功<a href='updata.asp?action=install'>安装</a>")
elseif action="install" then
str=openfile("config.txt")
if str="" then
response.write "缺少本地配置文件config.txt"
else
size=RegExpTest("size",str)
call install("pack.jpg",size)
end if
else
str=getpage(url&"config.txt")
if str="" then
response.write "不存在可用更新或者本地配置不正确"
response.end
end if
str1=openfile("config.txt")
if str1="" then
response.write "缺少本地配置文件config.txt无法获知本地程序的安装时间"
response.end
end if
updatatime=RegExpTest("time",str)
updatatime1=RegExpTest("time",str1)
if DateDiff("d",updatatime1,updatatime)>0 then
response.Write("存在可用更新,更新日期:"&updatatime&"<a href='updata.asp?action=updata'>下载</a>")
else
response.write "您的程序是最新的了"
end if
end if
function openfile(filename)
set fso=server.CreateObject("scripting.filesystemobject")
if fso.fileexists(server.MapPath(filename)) then
set f1=fso.opentextfile(server.mappath(filename),1,true)
openfile=f1.readall
f1.close
else
openfile=""
end if
set fso=nothing
end function
function getpage(url)
set xmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open "get",url,false
xmlhttp.send
if xmlhttp.status<>200 then
getpage=""
else
getpage=bytes2BSTR(xmlhttp.ResponseBody)
end if
end function
Function bytes2BSTR(vIn)
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
Function RegExpTest(patrn,strng)
Dim regEx,Match,Matches'建立变量。
Set regEx = New RegExp'建立正则表达式。
regEx.Pattern = patrn&"=(.+?)\n"'设置模式。
regEx.IgnoreCase = True'设置是否区分字符大小写。
regEx.Global = True'设置全局可用性。
Set Matches = regEx.Execute(strng)'执行搜索。
For Each Match in Matches'遍历匹配集合。
RetStr = Match.Value
Next
RegExpTest = replace(RetStr,patrn&"=","")
End Function
function download(url)
temp=split(url,"/")
filename=temp(ubound(temp))
set xmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open "get",url,false
xmlhttp.send
if xmlhttp.status<>200 then
download=""
else
set fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(server.mappath(filename)) then
fso.deletefile(server.mappath(filename))
end if
set fso=nothing
img=xmlhttp.ResponseBody
set objAdostream=server.createobject("ADODB.Stream")
objAdostream.Open
objAdost