用asp实现把文件打包成Xml文件包,带解包的ASP工具附下载
程序员文章站
2023-11-07 11:48:46
把文件打包成xml文件包,带解包的asp工具! 把网站源码全部打包到xml文件里面,生成 updata.xml 文件,把xml文件上传到空间里面 然后通...
把文件打包成xml文件包,带解包的asp工具!
把网站源码全部打包到xml文件里面,生成 updata.xml 文件,把xml文件上传到空间里面
然后通过 install.asp文件将文件全部释放出来。
就和z-blog的 自动安装包一样的功能呵呵。
代码是落伍的一位兄弟写的,不过代码好像有错误,这个是我参考他的 修改过了,可以正常运行!~~
此代码可以应用到 asp程序的 自动升级服务上面。具体怎么来实现,欢迎探讨!~~
就在下面回帖探讨!~~~
不用设定打包目录版,需要设定打包目录版 这两个版本的区别:
不用设定打包目录版,直接放到你需要打包的目录 执行就可以了。
需要设定打包目录版,必须指定需要打包的路径(在程序里修改),不指定,不能进行打包。
不用设定目录-打包文件
<%@language="vbscript" codepage="65001"%>
<% option explicit %>
<% on error resume next %>
<% response.charset="utf-8" %>
<% server.scripttimeout=99999999 %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>文件打包程序</title>
</head>
<body>
<%
dim zippathdir,zippathfile,zipfileext
dim startime,endtime
'在此更改要打包文件夹的路径
zippathdir = left(request.servervariables("path_translated"),instrrev(request.servervariables("path_translated"),"\"))'
'生成的xml文件
zippathfile = "update.xml"
'不进行打包的文件扩展名
zipfileext = "db;bak"
if right(zippathdir,1)<>"\" then zippathdir=zippathdir&"\"
'开始打包
createxml(zippathfile)
'遍历目录内的所有文件以及文件夹
sub loaddata(dirpath)
dim xmldoc
dim fso 'fso对象
dim objfolder '文件夹对象
dim objsubfolders '子文件夹集合
dim objsubfolder '子文件夹对象
dim objfiles '文件集合
dim objfile '文件对象
dim objstream
dim pathname,textstream,pp,xfolder,xfpath,xfile,xpath,xstream
dim pathnamestr
response.write("=========="&dirpath&"==========<br>")
set fso=server.createobject("scripting.filesystemobject")
set objfolder=fso.getfolder(dirpath)'创建文件夹对象
response.write dirpath
response.flush
set xmldoc = server.createobject("microsoft.xmldom")
xmldoc.load(server.mappath(zippathfile))
xmldoc.async=false
'写入每个文件夹路径
set xfolder = xmldoc.selectsinglenode("//root").appendchild(xmldoc.createelement("folder"))
set xfpath = xfolder.appendchild(xmldoc.createelement("path"))
xfpath.text = replace(dirpath,zippathdir,"")
set objfiles=objfolder.files
for each objfile in objfiles
if lcase(dirpath & objfile.name) <> lcase(request.servervariables("path_translated")) and lcase(dirpath & objfile.name) <> lcase(dirpath & zippathfile) then
if ext(objfile.name) then
response.write "---<br/>"
pathnamestr = dirpath & "" & objfile.name
response.write pathnamestr & ""
response.flush
'================================================
'写入文件的路径及文件内容
set xfile = xmldoc.selectsinglenode("//root").appendchild(xmldoc.createelement("file"))
set xpath = xfile.appendchild(xmldoc.createelement("path"))
xpath.text = replace(pathnamestr,zippathdir,"")
'创建文件流读入文件内容,并写入xml文件中
set objstream = server.createobject("adodb.stream")
objstream.type = 1
objstream.open()
objstream.loadfromfile(pathnamestr)
objstream.position = 0
set xstream = xfile.appendchild(xmldoc.createelement("stream"))
xstream.setattribute "xmlns:dt","urn:schemas-microsoft-com:datatypes"
'文件内容采用二制方式存放
xstream.datatype = "bin.base64"
xstream.nodetypedvalue = objstream.read()
set objstream=nothing
set xpath = nothing
set xstream = nothing
set xfile = nothing
'================================================
end if
end if
next
response.write "<p>"
xmldoc.save(server.mappath(zippathfile))
set xfpath = nothing
set xfolder = nothing
set xmldoc = nothing
'创建的子文件夹对象
set objsubfolders=objfolder.subfolders
'调用递归遍历子文件夹
for each objsubfolder in objsubfolders
pathname = dirpath & objsubfolder.name & "\"
loaddata(pathname)
next
set objfolder=nothing
set objsubfolders=nothing
set fso=nothing
end sub
'创建一个空的xml文件,为写入文件作准备
sub createxml(filepath)
'程序开始执行时间
startime=timer()
dim xmldoc,root
set xmldoc = server.createobject("microsoft.xmldom")
xmldoc.async = false
set root = xmldoc.createprocessinginstruction("xml","version='1.0' encoding='utf-8'")
xmldoc.appendchild(root)
xmldoc.appendchild(xmldoc.createelement("root"))
xmldoc.save(server.mappath(filepath))
set root = nothing
set xmldoc = nothing
loaddata(zippathdir)
'程序结束时间
endtime=timer()
response.write("页面执行时间:" & formatnumber((endtime-startime),3) & "秒")
end sub
'判断文件类型是否合法
function ext(filename)
ext = true
dim temp_ext,e
temp_ext = split(zipfileext,";")
for e=0 to ubound(temp_ext)
if mid(filename,instrrev(filename,".")+1)=temp_ext(e) then ext=false
next
end function
%>
</body>
</html>
解压asp文件
<%@language="vbscript" codepage="65001"%>
<% option explicit %>
<% on error resume next %>
<% response.charset="utf-8" %>
<% server.scripttimeout=99999999 %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>文件解包程序</title>
</head>
<body>
<%
dim strlocalpath
'得到当前文件夹的物理路径
strlocalpath=left(request.servervariables("path_translated"),instrrev(request.servervariables("path_translated"),"\"))
dim objxmlfile
dim objnodelist
dim objfso
dim objstream
dim i,j
set objxmlfile = server.createobject("microsoft.xmldom")
objxmlfile.load(server.mappath("update.xml"))
if objxmlfile.readystate=4 then
if objxmlfile.parseerror.errorcode = 0 then
set objnodelist = objxmlfile.documentelement.selectnodes("//folder/path")
set objfso = createobject("scripting.filesystemobject")
j=objnodelist.length-1
for i=0 to j
if objfso.folderexists(strlocalpath & objnodelist(i).text)=false then
objfso.createfolder(strlocalpath & objnodelist(i).text)
end if
response.write "创建目录" & objnodelist(i).text & "<br/>"
response.flush
next
set objfso = nothing
set objnodelist = nothing
set objnodelist = objxmlfile.documentelement.selectnodes("//file/path")
j=objnodelist.length-1
for i=0 to j
set objstream = createobject("adodb.stream")
with objstream
.type = 1
.open
.write objnodelist(i).nextsibling.nodetypedvalue
.savetofile strlocalpath & objnodelist(i).text,2
response.write "释放文件" & objnodelist(i).text & "<br/>"
response.flush
.close
end with
set objstream = nothing
next
set objnodelist = nothing
end if
end if
set objxmlfile = nothing
response.write "文件解包完毕"
%>
</body>
</html>
打包文件下载
把网站源码全部打包到xml文件里面,生成 updata.xml 文件,把xml文件上传到空间里面
然后通过 install.asp文件将文件全部释放出来。
就和z-blog的 自动安装包一样的功能呵呵。
代码是落伍的一位兄弟写的,不过代码好像有错误,这个是我参考他的 修改过了,可以正常运行!~~
此代码可以应用到 asp程序的 自动升级服务上面。具体怎么来实现,欢迎探讨!~~
就在下面回帖探讨!~~~
不用设定打包目录版,需要设定打包目录版 这两个版本的区别:
不用设定打包目录版,直接放到你需要打包的目录 执行就可以了。
需要设定打包目录版,必须指定需要打包的路径(在程序里修改),不指定,不能进行打包。
不用设定目录-打包文件
复制代码 代码如下:
<%@language="vbscript" codepage="65001"%>
<% option explicit %>
<% on error resume next %>
<% response.charset="utf-8" %>
<% server.scripttimeout=99999999 %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>文件打包程序</title>
</head>
<body>
<%
dim zippathdir,zippathfile,zipfileext
dim startime,endtime
'在此更改要打包文件夹的路径
zippathdir = left(request.servervariables("path_translated"),instrrev(request.servervariables("path_translated"),"\"))'
'生成的xml文件
zippathfile = "update.xml"
'不进行打包的文件扩展名
zipfileext = "db;bak"
if right(zippathdir,1)<>"\" then zippathdir=zippathdir&"\"
'开始打包
createxml(zippathfile)
'遍历目录内的所有文件以及文件夹
sub loaddata(dirpath)
dim xmldoc
dim fso 'fso对象
dim objfolder '文件夹对象
dim objsubfolders '子文件夹集合
dim objsubfolder '子文件夹对象
dim objfiles '文件集合
dim objfile '文件对象
dim objstream
dim pathname,textstream,pp,xfolder,xfpath,xfile,xpath,xstream
dim pathnamestr
response.write("=========="&dirpath&"==========<br>")
set fso=server.createobject("scripting.filesystemobject")
set objfolder=fso.getfolder(dirpath)'创建文件夹对象
response.write dirpath
response.flush
set xmldoc = server.createobject("microsoft.xmldom")
xmldoc.load(server.mappath(zippathfile))
xmldoc.async=false
'写入每个文件夹路径
set xfolder = xmldoc.selectsinglenode("//root").appendchild(xmldoc.createelement("folder"))
set xfpath = xfolder.appendchild(xmldoc.createelement("path"))
xfpath.text = replace(dirpath,zippathdir,"")
set objfiles=objfolder.files
for each objfile in objfiles
if lcase(dirpath & objfile.name) <> lcase(request.servervariables("path_translated")) and lcase(dirpath & objfile.name) <> lcase(dirpath & zippathfile) then
if ext(objfile.name) then
response.write "---<br/>"
pathnamestr = dirpath & "" & objfile.name
response.write pathnamestr & ""
response.flush
'================================================
'写入文件的路径及文件内容
set xfile = xmldoc.selectsinglenode("//root").appendchild(xmldoc.createelement("file"))
set xpath = xfile.appendchild(xmldoc.createelement("path"))
xpath.text = replace(pathnamestr,zippathdir,"")
'创建文件流读入文件内容,并写入xml文件中
set objstream = server.createobject("adodb.stream")
objstream.type = 1
objstream.open()
objstream.loadfromfile(pathnamestr)
objstream.position = 0
set xstream = xfile.appendchild(xmldoc.createelement("stream"))
xstream.setattribute "xmlns:dt","urn:schemas-microsoft-com:datatypes"
'文件内容采用二制方式存放
xstream.datatype = "bin.base64"
xstream.nodetypedvalue = objstream.read()
set objstream=nothing
set xpath = nothing
set xstream = nothing
set xfile = nothing
'================================================
end if
end if
next
response.write "<p>"
xmldoc.save(server.mappath(zippathfile))
set xfpath = nothing
set xfolder = nothing
set xmldoc = nothing
'创建的子文件夹对象
set objsubfolders=objfolder.subfolders
'调用递归遍历子文件夹
for each objsubfolder in objsubfolders
pathname = dirpath & objsubfolder.name & "\"
loaddata(pathname)
next
set objfolder=nothing
set objsubfolders=nothing
set fso=nothing
end sub
'创建一个空的xml文件,为写入文件作准备
sub createxml(filepath)
'程序开始执行时间
startime=timer()
dim xmldoc,root
set xmldoc = server.createobject("microsoft.xmldom")
xmldoc.async = false
set root = xmldoc.createprocessinginstruction("xml","version='1.0' encoding='utf-8'")
xmldoc.appendchild(root)
xmldoc.appendchild(xmldoc.createelement("root"))
xmldoc.save(server.mappath(filepath))
set root = nothing
set xmldoc = nothing
loaddata(zippathdir)
'程序结束时间
endtime=timer()
response.write("页面执行时间:" & formatnumber((endtime-startime),3) & "秒")
end sub
'判断文件类型是否合法
function ext(filename)
ext = true
dim temp_ext,e
temp_ext = split(zipfileext,";")
for e=0 to ubound(temp_ext)
if mid(filename,instrrev(filename,".")+1)=temp_ext(e) then ext=false
next
end function
%>
</body>
</html>
解压asp文件
复制代码 代码如下:
<%@language="vbscript" codepage="65001"%>
<% option explicit %>
<% on error resume next %>
<% response.charset="utf-8" %>
<% server.scripttimeout=99999999 %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>文件解包程序</title>
</head>
<body>
<%
dim strlocalpath
'得到当前文件夹的物理路径
strlocalpath=left(request.servervariables("path_translated"),instrrev(request.servervariables("path_translated"),"\"))
dim objxmlfile
dim objnodelist
dim objfso
dim objstream
dim i,j
set objxmlfile = server.createobject("microsoft.xmldom")
objxmlfile.load(server.mappath("update.xml"))
if objxmlfile.readystate=4 then
if objxmlfile.parseerror.errorcode = 0 then
set objnodelist = objxmlfile.documentelement.selectnodes("//folder/path")
set objfso = createobject("scripting.filesystemobject")
j=objnodelist.length-1
for i=0 to j
if objfso.folderexists(strlocalpath & objnodelist(i).text)=false then
objfso.createfolder(strlocalpath & objnodelist(i).text)
end if
response.write "创建目录" & objnodelist(i).text & "<br/>"
response.flush
next
set objfso = nothing
set objnodelist = nothing
set objnodelist = objxmlfile.documentelement.selectnodes("//file/path")
j=objnodelist.length-1
for i=0 to j
set objstream = createobject("adodb.stream")
with objstream
.type = 1
.open
.write objnodelist(i).nextsibling.nodetypedvalue
.savetofile strlocalpath & objnodelist(i).text,2
response.write "释放文件" & objnodelist(i).text & "<br/>"
response.flush
.close
end with
set objstream = nothing
next
set objnodelist = nothing
end if
end if
set objxmlfile = nothing
response.write "文件解包完毕"
%>
</body>
</html>
打包文件下载
下一篇: 七步倒┈→专用asp后门