当前位置: 移动技术网 > IT编程>开发语言>.net > ASP网站程序自动升级实现的方法

ASP网站程序自动升级实现的方法

2018年11月07日  | 移动技术网IT编程  | 我要评论

闰月结婚好吗,鳌江,xingqingzhongren

现在流行虚拟主机建站,我也有个网站,也算是个咯。当了近一年的站长,感到网站程序每次升级的时候颇为麻烦:先去官方看公告,然后下载升级包到本地,解压,ftp上传到虚拟主机。这些都是累人的体力活,加之本人又懒得很,所以异想天开的觉得要是程序能够自动升级就好了。所以就想了想,写了本文,希望对web者有帮助。这里只针对asp,因为我只会asp :-(

先看看传统的win32程序的升级过程(比如软件),它是依靠软件的升级程序通过网络连接到服务器分析并下载升级文件到本地。

web程序有点不一样,因为它是运行于web服务器。它最终是要把升级服务器上的文件覆盖到web服务器,站长的电脑只是中转。如果直接把升级服务器上的文件copy到web服务器(而不通过站长中转)那就实现了自动升级。

好在自带了一个 microsoft.xmlhttp 用于访问web,在asp中可以调用它来实现连接升级服务器下载升级文件。

以下代码是利用 microsoft.xmlhttp下载文件的例子:

<%
set xpost = createobject("microsoft.xmlhttp")
         xpost.open "get","
         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("下载文件成功!<br>")
%>

上面代码就是把 保存到web服务器当前目录,至于microsoft.xmlhttp 的更多用法还是看看msdn吧。

如果文件比较多,就会多次调用microsoft.xmlhttp连接网络,就可能出现某次连接失败部分文件未能更新的情况,为了避免这种情况,最好是把所有文件打包为一个文件一次下载到web后再解包。
呵呵,这里说的打包可不是rar或者zip包,而是我们自己定义。比如把所有文件拼接为一个,然后再根据特殊的记号分开。现在没这么麻烦咯,因为有个现成的办法,我们使用拿来主义就是:把所有文件(二进制形式)及其路径信息放入access。

下面这个vbs文件(来自海洋顶端2006plus)就是打包当前目录的所有文件的:

       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 "当前目录已经打包完毕,根目录为当前目录"
         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 ins

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网