ASP online upgrade program

xiaoxiao2021-03-06  96

ASP online upgrade program <% 'file name: Updata.asp' remote address const url = "http: // localhost / test /"

Action = Request ("action") if action = "Updata" the Download (URL & "config.txt") Download (URL & "Pack.jpg") Response.write ("Download Success is mounted ") elseif action =" install "then str = openfile (" config.txt ") if str =" "then response.write" missing local configuration file config.txt "else size = RegExpTest ( "size", str) call install ( "pack.jpg", size) end ifelse str = getpage (url & "config.txt") if str = "" then response.write "no update is available locally or incorrectly configured "Response.end end IF

Str1 = OpenFile ("config.txt") if str1 = "" "" "" "" "" response.end endiff "lack of local profile config.txt cannot know the installation time of the local program

UpDataTime = Regexptest ("Time", Str) UpdataTime1 = Regexptest ("Time", Str1)

If Datediff ("D", UpDataTime1, Updataime> 0 Then Response.write ("There is available updates, updated, update date:" & updata.asp?A href='updata.asp?action=updata'> Download ") Else Response.write "Your program is the latest" End IFEND 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.closeelse Openfile = "" end ifset fso = nothingnd function

function getpage (url) set xmlhttp = server.createobject ( "Microsoft.XMLHTTP") xmlhttp.open "get", url, falsexmlhttp.sendif xmlhttp.status <> 200 then getpage = "" else getpage = bytes2BSTR (xmlhttp.ResponseBody) end ifend functionFunction bytes2BSTR (vIn) dim strReturndim i, ThisCharCode, NextCharCodestrReturn = "" For i = 1 To LenB (vIn) ThisCharCode = AscB (MidB (vIn, i, 1)) If ThisCharCode <& H80 ThenstrReturn = strReturn & Chr (ThisCharCode ElsenextCharcode = ASCB (MIDB (VIN, I 1, 1)) Strreturn = Strreturn & Chr (ClNG (thischarcode) * & H100 CINT (NEXTCHARCODE)) i = i 1END IFNEXTBYTES2BSTR = STRRETURNEEND FUNCTION

Function Regexptest (PATRN, STRNG) DIM Regex, Match, Matches' establishes variables. Set regex = new regexp 'establishes regular expressions. Regex.pattern = PATRN & "= (. ?) / n" set mode. Regex.ignoreCase = true 'Set whether you distinguish between characters. Regex.global = true 'Sets global availability. Set matches = regex.execute (strng) 'Executes your search. FOR Each Match In Matches' traverses matching collection. Retstr = match.valueneXTRegexptest = 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 objAdostream.type = 1 objAdostream.Write (img) objAdostream.SaveToFile (server.mappath (filename)) objAdostream .Seos set objadostream = Nothing Download = filename endiff = Nothingend FunctionFunction Install (filename, size) on error resume nextpath = server.mAppath ("./")

SET FSO = Server.createObject ("scripting.filesystemObject")

SET S = Server.createObject ("AdoDb.Stream") Set S1 = Server.createObject ("AdoDb.Stream") Set S2 = Server.createObject ("AdoDb.Stream")

S.Opens1.opens2.open

S.TYPE = 1S1.TYPE = 1S2.TYPE = 1

S.LoadFromFile (server.mappath (filename)) s.position = sizes1.write (sready) s1.position = 0s1.type = 2s1.Charset = "gb2312" s1.position = 0A = split (S1.ReadText, VBCRLF) s.Position = 0

I = 0WHILE (i ") IF b (0) = "folder" Then if not fso.folderexists (Path & B (2)) THEN FSO.CREATEFOLDER PATH & B (2)) End if elseif B (0) = "File" Then IF fso.fileexists (Path & B)) THEN FSO.DELETEFILE (PATH & B (2)) end if s2.position = 0 s2.write (s. Read (b (1)))) S2.seos S2.Savetofile (Path & B (2)) end if i = i 1WENDS.CloseS1.closeS2.Closset S = NothingSet S1 = NothingSet S2 = NothingSet Fso = Nothingif Err.Number <> 0 Then Response.write Err.Descriptionelse response.write "installation success" end ifnd function

%>

<% 'File name: Pack.aspon error resume next.com fso = server.createObject ("scripting.filesystemObject") if fso.mappath ("./ pack.jpg") The Response.write ("Pack. JPG already exists ") Response.end () endiff

DIM STR, S, S1, S2SET S = Server.createObject ("AdoDb.Stream") Set S1 = Server.createObject ("AdoDb.Stream") Set S2 = Server.createObject ("AdoDb.Stream")

S.Opens1.opens2.open

S.TYPE = 1S1.TYPE = 1S2.TYPE = 2

Call writefile (Server.MAppath ("./"))

S2.Charset = "GB2312" S2.Writetext (str) s2.position = 0s2.type = 1s2.position = 0bin = s2.read

S2.Position = 0s2.type = 2s2.writetext ("Time =" & NOW & VBCRLF) S2.Writetext ("SIZE =" & S1.Size & VBCRLF) S2.WriteText ("Run =" & Request.Form ("RUN" & VBCRLF) S2. Seteoss2.savetofile (Server.mAppath ("./ Config.txt"))))

S1.write (bin) s1.seteoss1.savetofile (Server.MAppath ("./ pack.jpg")))

S.closeS1.closeS2.Close

SET S = NothingSet S1 = NothingSet S2 = Nothing

if err.number <> 0 then response.write err.descriptionelse response.Write ( "complete") end ifFunction WriteFile (folderspec) Set fso = CreateObject ( "Scripting.FileSystemObject") Set f = fso.GetFolder (folderspec)

SET FC = F.FILESFOR EACH F1 IN FC IF F1.NAME <> "Pack.ASP" THEN STR = Str & "File>" & F1.Size & "File> & Replace (Folderspec &" / "& f1.name, server.mappath (" ./")"" "&vbcrlf s.loadFromfile (folderspec & "/" & f1.name) img = s.read () s1.write (img) end ifxT

SET FC = F.Subfoldersfor Each F1 in FC Str = Str & "Folder> 0>" & Replace (Folderspec & "/" & f1.name, server.mappath (".", """ "& f1 .name) Next

SET FSO = Nothingend Function%>

ASP upgrade program instructions

This procedure is divided into two parts: 1. ASP file package Pack.asp put this program and put the program to package in a directory, then run Pack.asp, get pack.jpg and config.txt2, ASP online update, download, Installer Updata.asp This program can be used to check if there is available updates, and the same directory with Updata.asp exists above config.txt, because there is a current program installation date in Config, used to compare with the online program . Before use, modify the value of the URL variable in the updata.asp, so that it is equal to the URL you store the upgrade program, run Updata.asp to see if there is available updates, if there is, you can use the wizard step by step to download and install updates .

Remote address URL Save pack.jpg and config.txt available with Pack.asp

This program can be used to do upgrade procedures, of course, if the original installation directory is empty, it is a complete installer, ^ _ ^, you can also put UpData.asp in the home page of the background, so each login Can automatically check if there is available update

Note: Local or remote without config.txt will cause the program to be unavailable, and will consider adding this fault tolerance mechanism.

转载请注明原文地址:https://www.9cbs.com/read-105550.html

New Post(0)