ASP program to achieve automatic upgrade function _ Thieves/collection

Source: Internet
Author: User
Tags unpack
Now the popular virtual host station, I also have a website, is also a webmaster slightly. When the webmaster for nearly a year, feel the site program every time the upgrade is quite troublesome: first go to the official notice, and then download the upgrade package to the local, decompression, FTP upload to the virtual host. These are tiring physical work, plus I am lazy, so the whimsical feel that if the program can automatically upgrade the good. So think about it, write this article, want to be helpful to the Web application developer. This is only for ASP, because I will only:-(ASP
First look at the traditional Win32 program upgrade process (such as anti-virus software), which relies on software upgrades through the network to connect to the server analysis and download the upgrade file to the local.
The Web program is a little different because it is running on a Web server. It is ultimately to upgrade the server to cover the file to the Web server, the webmaster's computer is only a relay. If you copy the files on the upgrade server directly to the Web server (instead of passing through the webmaster), the automatic upgrade is achieved.
Fortunately, the system has a microsoft.xmlhttp component to access the Web, in the ASP can call it to implement the connection upgrade server download upgrade files.
The following code is an example of downloading a file using Microsoft.XMLHTTP:

<%
Set Xpost = CreateObject ("Microsoft.XMLHTTP")
Xpost.open "Get", "Http://www.0x54.org/test.exe", False
Xpost.send ()
Set Sget = CreateObject ("ADODB. Stream ")
Sget.mode = 3
Sget.type = 1
Sget.open ()
Sget.write (Xpost.responsebody)
Sget.savetofile Server.MapPath ("Update.exe"), 2
Set sget = Nothing
Set spost = Nothing
Response. Write ("Download file successful!") <br> ")
%>


The code above is to save the Http://www.0x54.org/test.exe to the Web server's current directory, and for more usage of microsoft.xmlhttp, check out MSDN.
If there are more files, the Microsoft.XMLHTTP connection network will be called more than once, and there may be a failure to update some of the connection files, in order to avoid this situation, it is best to package all the files to a file once downloaded to the web and then unpack.
Oh, the package is not a RAR or zip package, but our own definition. For example, all files are spliced into one, and then separated by special markings. Not so much trouble now, because there is a ready-made way, we use copycat is: all the files (binary form) and its path information into the Access database.
The following VBS file (from Ocean top 2006Plus) is the package for all files in the current directory:

Dim N, WS, Fsox, Thepath
Set ws = CreateObject ("Wscript.Shell")
Set Fsox = CreateObject ("Scripting.FileSystemObject")
Thepath = ws. Exec ("cmd/c CD"). Stdout.readall () & "\"
i = InStr (Thepath, CHR (13))
Thepath = Left (Thepath, i-1)
n = Len (thepath)
On Error Resume Next
Addtomdb (Thepath)
WScript.Echo "Current directory is packaged, root directory is current directory"
Sub Addtomdb (Thepath)
Dim RS, Conn, stream, ConnStr
Set rs = CreateObject ("ADODB.") RecordSet ")
Set stream = CreateObject ("ADODB.") Stream ")
Set conn = CreateObject ("ADODB. Connection ")
Set Adocatalog = CreateObject ("ADOX. Catalog ")
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=packet.mdb "
Adocatalog.create ConnStr
Conn. Open ConnStr
Conn. Execute ("Create Table filedata (Id int IDENTITY (0,1) PRIMARY KEY CLUSTERED, P Text, filecontent Image)"
Stream. Open
Stream. Type = 1
Rs. Open "Filedata", Conn, 3, 3
Fsotreeformdb Thepath, RS, stream
Rs. Close
Conn.close
Stream. Close
Set rs = Nothing
Set conn = Nothing
Set stream = Nothing
Set Adocatalog = Nothing
End Sub
Function Fsotreeformdb (Thepath, RS, stream)
Dim I, item, Thefolder, folders, files
Sysfilelist = "$" & WScript.ScriptName & "$Packet. mdb$packet.ldb$"
Set Thefolder = Fsox.getfolder (thepath)
Set files = thefolder.files
Set folders = Thefolder.subfolders
For each item in folders
Fsotreeformdb item. Path, RS, stream
Next
For each item in files
If InStr (LCase (Sysfilelist), "$" & LCase (item. Name) & "$") <= 0 Then
Rs. AddNew
RS ("P") = Mid (item. Path, n + 2)
Stream. LoadFromFile (item. Path)
RS ("filecontent") = stream. Read ()
Rs. Update
End If
Next
Set files = Nothing
Set folders = Nothing
Set Thefolder = Nothing
End Function


The following is an ASP file for the solution package:

<%
Sub Unpack ()
str = Server.MapPath (".") & "\"
Set rs = CreateObject ("ADODB.") RecordSet ")
Set stream = CreateObject ("ADODB.") Stream ")
Set conn = CreateObject ("ADODB. Connection ")
Set oFSO = CreateObject ("Scripting.FileSystemObject")
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("Update.mdb")
Conn. Open ConnStr
Rs. Open "Filedata", Conn, 1, 1
Stream. Open
Stream. Type = 1
Do Until Rs. Eof
Thefolder = Left (rs ("P"), InStrRev (RS ("P"), "\")
If ofso.folderexists (str & thefolder) = False Then
Ofso.createfolder (str & thefolder)
End If
Stream. SetEOS ()
If IsNull (RS ("filecontent")) = False Then stream. Write rs ("Filecontent")
Stream. SaveToFile Str & RS ("P"), 2
Rs. MoveNext
Loop
Rs. Close
Conn. Close
Stream. Close
Set ws = Nothing
Set rs = Nothing
Set stream = Nothing
Set conn = Nothing
Set oFSO = Nothing
End Sub
%>


Well, with the above code is not difficult to issue their own ASP upgrade procedures, the process is not the case: to determine whether the need to upgrade (Y)-> Download Upgrade package-> Undo Upgrade Package Overwrite old files-> Delete upgrade Package-> update version information-> OK
It's almost the end of the story, and some of the details, such as version judgments, skip over.
Hope that the early use of automatic upgrade of various types of Web programs, but also so that I wait for lazy people happy leisurely, haha.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.