不用WinRar只有asp将网络空间上的文件打包下载
2018-09-06 11:38
<%@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
Co=Co+1
Next
ForEachxIntheSubFolders
ForEachiInX.Files
Temp=Temp&X.Name&/&i.Name&
Co=Co+1
Next
Next
IfCo<1Then
Response.Write暂时没有可更新的文件下载
objTar.AddMemoryFileSorry.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
whichallowsmetograb100sofdynamicallycreatedXMLfilesinasingledownload.
Thereareasmallnumberofpropertiesandmethods,whichareoutlinedinthe
accompanyingdocumentation.
ClassTarball
PublicTarFilenameResultanttarballfilename
PublicUserIDUNIXuserID
PublicUserNameUNIXusername
PublicGroupIDUNIXgroupID
PublicGroupNameUNIXgroupname
PublicPermissionsUNIXpermissions
PublicBlockSizeBlockbytesizeforthetarball(default=512)
PublicIgnorePathsIgnoreanysuppliedpathsforthetarballoutput
PublicBasePathInsertabasepathwitheachfile
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-ansiGoodoldextendedASCII
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.AddHeaderContent-Disposition,filename=&TarFilename
Response.BinaryWriteobjStream.Read
Closeitandgohome
objStream.Close
SetobjStream=Nothing
SetobjInStream=Nothing
EndSub
Buildaheaderforeachfileandsendthefilecontents
PrivateSubExportFile(sFilename,objOutStream,objInStream)
DimlStart,lSum,lTemp
lStart=objOutStream.PositionRecordwhereweareupto
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.WriteText100&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.WriteText0&String(100,Chr(0))chksum,typeflagandlinkname,writeoutallblankssothattheactualchecksumwillgetcalculatedcorrectly
objOutStream.WriteTextustar&Chr(0)magicandversion
objOutStream.WriteTextLeft(UserName&String(32,Chr(0)),32)uname
objOutStream.WriteTextLeft(GroupName&String(32,Chr(0)),32)gname
objOutStream.WriteText40&String(4,Chr(0))devmajor,devminor
objOutStream.WriteTextString(167,Chr(0))prefixandleader
objInStream.CopyToobjOutStreamSendthedatatothestream
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=438UNIX666
UserID=0
UserName=root
GroupID=0
GroupName=root
IgnorePaths=False
BasePath=
TarFilename=new.tar
EndSub
PrivateSubClass_Terminate()
SetobjMemoryFiles=Nothing
SetobjFiles=Nothing
EndSub
EndClass
%>
下一篇:自动采集程序
文章标题:不用WinRar只有asp将网络空间上的文件打包下载
文章链接:http://soscw.com/index.php/essay/9572.html