- <%@Language=VBScript%>
- <%OptionExplicit%>
- <!–#includefile="asptar.asp"–>
- <%
- Response.Buffer=True
- Response.Clear
- DimCo,Temp,T,x,i,fsoBrowse,theFolder,TheSubFolders,FilePath,s,PH,objTar
- Co=0
- PH="./UpFile"'文件路径'压缩Upfile下的所有文件
- SetobjTar=NewTarball
- objTar.TarFilename="LvBBS_UpdateFile.rar"'打包的名称
- objTar.Path=PH
- setfsoBrowse=CreateObject("Scripting.FileSystemObject")
- SettheFolder=fsoBrowse.GetFolder(Server.Mappath(PH))
- SettheSubFolders=theFolder.SubFolders
- ForEachTintheFolder.Files
- Temp=Temp&T.Name&"|"
- Co=Co+1
- Next
- ForEachxIntheSubFolders
- ForEachiInX.Files
- Temp=Temp&X.Name&"/"&i.Name&"|"
- Co=Co+1
- Next
- Next
- IfCo<1Then
- Response.Write"暂时没有可更新的文件下载"
- 'objTar.AddMemoryFile"Sorry.txt","NotFile!"
- Else
- Temp=Left(Temp,Len(Temp)-1)
- FilePath=Split(Temp,"|")
- Fors=0ToUbound(FilePath)
- objTar.AddFileServer.Mappath(PH&"/"&FilePath(s))
- Next
- IfResponse.IsClientConnectedThen
- objTar.WriteTar
- Response.Flush
- EndIf
- EndIf
- SetObjTar=Nothing
- SetfsoBrowse=Nothing
- SettheFolder=Nothing
- SettheSubFolders=Nothing
- %>
- asptar.asp
- <%
- 'UNIXTarballcreator
- '====================
- 'Author:ChrisRead
- 'Version:1.0.1
- '====================
- '
- 'Thisclassprovidestheabilitytoarchivemultiplefilestogetherintoasingle
- 'distributablefilecalledatarball(TheTARactuallystandsforTapeARchive).
- 'ThesearecommonUNIXfileswhichcontainuncompresseddata.
- '
- 'Sowhatisthisusefulfor?Well,itallowsyoutoeffectivelycombinemultiple
- 'filesintoasinglefilefordownloading.TheTARfilesarereadableandextractable
- 'byawidevarietyoftools,includingtheverywidelydistributedWinZip.
- '
- 'Thisscriptcanincludetwotypesofdataineacharchive,filedatareadfromadisk,
- 'andalsothingsdirectfrommemory,likefromastring.Thearchivessupportfilesin
- 'abinarystructure,soyoucanstoreexecutablefilesifyouneedto,orjuststore
- 'text.
- '
- 'Thisclasswasdevelopedtoassistmewithafewprojectsandhasgrownwithevery
- 'implementation.CurrentlyIusethisclasstotarballXMLdataforarchivalpurposes
- 'whichallowsmetograb100'sofdynamicallycreatedXMLfilesinasingledownload.
- '
- 'Thereareasmallnumberofpropertiesandmethods,whichareoutlinedinthe
- 'accompanyingdocumentation.
- '
- ClassTarball
- PublicTarFilename'Resultanttarballfilename
- PublicUserID'UNIXuserID
- PublicUserName'UNIXusername
- PublicGroupID'UNIXgroupID
- PublicGroupName'UNIXgroupname
- PublicPermissions'UNIXpermissions
- PublicBlockSize'Blockbytesizeforthetarball(default=512)
- PublicIgnorePaths'Ignoreanysuppliedpathsforthetarballoutput
- PublicBasePath'Insertabasepathwitheachfile
- PublicPath
- 'Storageforfileinformation
- PrivateobjFiles,TmpFileName
- PrivateobjMemoryFiles
- 'Filelistmanagementsubs,verybasicstuff
- PublicSubAddFile(sFilename)
- objFiles.AddsFilename,sFilename
- EndSub
- PublicSubRemoveFile(sFilename)
- objFiles.RemovesFilename
- EndSub
- PublicSubAddMemoryFile(sFilename,sContents)
- objMemoryFiles.AddsFilename,sContents
- EndSub
- PublicSubRemoveMemoryFile(sFilename)
- objMemoryFiles.RemovesFilename
- EndSub
- 'Sendthetarballtothebrowser
- PublicSubWriteTar()
- DimobjStream,objInStream,lTemp,aFiles
- SetobjStream=Server.CreateObject("ADODB.Stream")'Themainstream
- SetobjInStream=Server.CreateObject("ADODB.Stream")'Theinputstreamfordata
- objStream.Type=2
- objStream.Charset="x-ansi"'GoodoldextendedASCII
- objStream.Open
- objInStream.Type=2
- objInStream.Charset="x-ansi"
- 'Gothroughallfilesstoredondiskfirst
- aFiles=objFiles.Items
- ForlTemp=0toUBound(aFiles)
- objInStream.Open
- objInStream.LoadFromFileaFiles(lTemp)
- objInStream.Position=0
- 'ExportFileaFiles(lTemp),objStream,objInStream
- TmpFileName=replace(aFiles(lTemp),Server.Mappath(Path)&"\\","")
- ExportFileTmpFileName,objStream,objInStream
- objInStream.Close
- Next
- 'Nowaddstufffrommemory
- aFiles=objMemoryFiles.Keys
- ForlTemp=0toUBound(aFiles)
- objInStream.Open
- objInStream.WriteTextobjMemoryFiles.Item(aFiles(lTemp))
- objInStream.Position=0
- ExportFileaFiles(lTemp),objStream,objInStream
- objInStream.Close
- Next
- objStream.WriteTextString(BlockSize,Chr(0))
- 'Rewindthestream
- 'Remembertochangethetypebacktobinary,otherwisethewritewilltruncate
- 'pastthefirstzerobytecharacter.
- objStream.Position=0
- objStream.Type=1
- 'Setallthebrowserstuff
- Response.AddHeader"Content-Disposition","filename="&TarFilename
- Response.ContentType="application/x-tar"
- Response.BinaryWriteobjStream.Read
- 'Closeitandgohome
- objStream.Close
- SetobjStream=Nothing
- SetobjInStream=Nothing
- EndSub
- 'Buildaheaderforeachfileandsendthefilecontents
- PrivateSubExportFile(sFilename,objOutStream,objInStream)
- DimlStart,lSum,lTemp
- lStart=objOutStream.Position'Recordwhereweareupto
- IfIgnorePathsThen
- 'Weignoreanypathsprefixedtoourfilenames
- lTemp=InStrRev(sFilename,"\\")
- iflTemp<>0then
- sFilename=Right(sFilename,Len(sFilename)-lTemp)
- endif
- sFilename=BasePath&sFilename
- EndIf
- 'Buildtheheader,everythingisASCIIinoctalexceptforthedata
- objOutStream.WriteTextLeft(sFilename&String(100,Chr(0)),100)
- objOutStream.WriteText"100"&Right("000"&Oct(Permissions),3)&""&Chr(0)'Filemode
- objOutStream.WriteTextRight(String(6,"")&CStr(UserID),6)&""&Chr(0)'uid
- objOutStream.WriteTextRight(String(6,"")&CStr(GroupID),6)&""&Chr(0)'gid
- objOutStream.WriteTextRight(String(11,"0")&Oct(objInStream.Size),11)&Chr(0)'size
- objOutStream.WriteTextRight(String(11,"0")&Oct(dateDiff("s","1/1/197010:00",now())),11)&Chr(0)'mtime(Numberofsecondssince10amonthe1stJanuary1970(10amcorrect?)
- objOutStream.WriteText"0"&String(100,Chr(0))'chksum,typeflagandlinkname,writeoutallblankssothattheactualchecksumwillgetcalculatedcorrectly
- objOutStream.WriteText"ustar"&Chr(0)'magicandversion
- objOutStream.WriteTextLeft(UserName&String(32,Chr(0)),32)'uname
- objOutStream.WriteTextLeft(GroupName&String(32,Chr(0)),32)'gname
- objOutStream.WriteText"40"&String(4,Chr(0))'devmajor,devminor
- objOutStream.WriteTextString(167,Chr(0))'prefixandleader
- objInStream.CopyToobjOutStream'Sendthedatatothestream
- if(objInStream.SizeModBlockSize)>0then
- objOutStream.WriteTextString(BlockSize-(objInStream.SizeModBlockSize),Chr(0))'Paddingtothenearestblockbyteboundary
- endif
- 'Calculatethechecksumfortheheader
- lSum=0
- objOutStream.Position=lStart
- ForlTemp=1ToBlockSize
- lSum=lSum+(Asc(objOutStream.ReadText(1))And&HFF&)
- Next
- 'Insertit
- objOutStream.Position=lStart+148
- objOutStream.WriteTextRight(String(7,"0")&Oct(lSum),7)&Chr(0)
- 'Movetotheendofthestream
- objOutStream.Position=objOutStream.Size
- EndSub
- 'Starteverythingoff
- PrivateSubClass_Initialize()
- SetobjFiles=Server.CreateObject("Scripting.Dictionary")
- SetobjMemoryFiles=Server.CreateObject("Scripting.Dictionary")
- BlockSize=512
- Permissions=438'UNIX666
- UserID=0
- UserName="root"
- GroupID=0
- GroupName="root"
- IgnorePaths=False
- BasePath=""
- TarFilename="new.tar"
- EndSub
- PrivateSubClass_Terminate()
- SetobjMemoryFiles=Nothing
- SetobjFiles=Nothing
- EndSub
- EndClass
- %>
相关文章
猜你喜欢
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10