不用WinRar只有asp将网络空间上的文件打包下载

2025-05-27 0 45
  1. <%@Language=VBScript%>
  2. <%OptionExplicit%>
  3. <!–#includefile="asptar.asp"–>
  4. <%
  5. Response.Buffer=True
  6. Response.Clear
  7. DimCo,Temp,T,x,i,fsoBrowse,theFolder,TheSubFolders,FilePath,s,PH,objTar
  8. Co=0
  9. PH="./UpFile"'文件路径'压缩Upfile下的所有文件
  10. SetobjTar=NewTarball
  11. objTar.TarFilename="LvBBS_UpdateFile.rar"'打包的名称
  12. objTar.Path=PH
  13. setfsoBrowse=CreateObject("Scripting.FileSystemObject")
  14. SettheFolder=fsoBrowse.GetFolder(Server.Mappath(PH))
  15. SettheSubFolders=theFolder.SubFolders
  16. ForEachTintheFolder.Files
  17. Temp=Temp&T.Name&"|"
  18. Co=Co+1
  19. Next
  20. ForEachxIntheSubFolders
  21. ForEachiInX.Files
  22. Temp=Temp&X.Name&"/"&i.Name&"|"
  23. Co=Co+1
  24. Next
  25. Next
  26. IfCo<1Then
  27. Response.Write"暂时没有可更新的文件下载"
  28. 'objTar.AddMemoryFile"Sorry.txt","NotFile!"
  29. Else
  30. Temp=Left(Temp,Len(Temp)-1)
  31. FilePath=Split(Temp,"|")
  32. Fors=0ToUbound(FilePath)
  33. objTar.AddFileServer.Mappath(PH&"/"&FilePath(s))
  34. Next
  35. IfResponse.IsClientConnectedThen
  36. objTar.WriteTar
  37. Response.Flush
  38. EndIf
  39. EndIf
  40. SetObjTar=Nothing
  41. SetfsoBrowse=Nothing
  42. SettheFolder=Nothing
  43. SettheSubFolders=Nothing
  44. %>
  45. asptar.asp
  46. <%
  47. 'UNIXTarballcreator
  48. '====================
  49. 'Author:ChrisRead
  50. 'Version:1.0.1
  51. '====================
  52. '
  53. 'Thisclassprovidestheabilitytoarchivemultiplefilestogetherintoasingle
  54. 'distributablefilecalledatarball(TheTARactuallystandsforTapeARchive).
  55. 'ThesearecommonUNIXfileswhichcontainuncompresseddata.
  56. '
  57. 'Sowhatisthisusefulfor?Well,itallowsyoutoeffectivelycombinemultiple
  58. 'filesintoasinglefilefordownloading.TheTARfilesarereadableandextractable
  59. 'byawidevarietyoftools,includingtheverywidelydistributedWinZip.
  60. '
  61. 'Thisscriptcanincludetwotypesofdataineacharchive,filedatareadfromadisk,
  62. 'andalsothingsdirectfrommemory,likefromastring.Thearchivessupportfilesin
  63. 'abinarystructure,soyoucanstoreexecutablefilesifyouneedto,orjuststore
  64. 'text.
  65. '
  66. 'Thisclasswasdevelopedtoassistmewithafewprojectsandhasgrownwithevery
  67. 'implementation.CurrentlyIusethisclasstotarballXMLdataforarchivalpurposes
  68. 'whichallowsmetograb100'sofdynamicallycreatedXMLfilesinasingledownload.
  69. '
  70. 'Thereareasmallnumberofpropertiesandmethods,whichareoutlinedinthe
  71. 'accompanyingdocumentation.
  72. '
  73. ClassTarball
  74. PublicTarFilename'Resultanttarballfilename
  75. PublicUserID'UNIXuserID
  76. PublicUserName'UNIXusername
  77. PublicGroupID'UNIXgroupID
  78. PublicGroupName'UNIXgroupname
  79. PublicPermissions'UNIXpermissions
  80. PublicBlockSize'Blockbytesizeforthetarball(default=512)
  81. PublicIgnorePaths'Ignoreanysuppliedpathsforthetarballoutput
  82. PublicBasePath'Insertabasepathwitheachfile
  83. PublicPath
  84. 'Storageforfileinformation
  85. PrivateobjFiles,TmpFileName
  86. PrivateobjMemoryFiles
  87. 'Filelistmanagementsubs,verybasicstuff
  88. PublicSubAddFile(sFilename)
  89. objFiles.AddsFilename,sFilename
  90. EndSub
  91. PublicSubRemoveFile(sFilename)
  92. objFiles.RemovesFilename
  93. EndSub
  94. PublicSubAddMemoryFile(sFilename,sContents)
  95. objMemoryFiles.AddsFilename,sContents
  96. EndSub
  97. PublicSubRemoveMemoryFile(sFilename)
  98. objMemoryFiles.RemovesFilename
  99. EndSub
  100. 'Sendthetarballtothebrowser
  101. PublicSubWriteTar()
  102. DimobjStream,objInStream,lTemp,aFiles
  103. SetobjStream=Server.CreateObject("ADODB.Stream")'Themainstream
  104. SetobjInStream=Server.CreateObject("ADODB.Stream")'Theinputstreamfordata
  105. objStream.Type=2
  106. objStream.Charset="x-ansi"'GoodoldextendedASCII
  107. objStream.Open
  108. objInStream.Type=2
  109. objInStream.Charset="x-ansi"
  110. 'Gothroughallfilesstoredondiskfirst
  111. aFiles=objFiles.Items
  112. ForlTemp=0toUBound(aFiles)
  113. objInStream.Open
  114. objInStream.LoadFromFileaFiles(lTemp)
  115. objInStream.Position=0
  116. 'ExportFileaFiles(lTemp),objStream,objInStream
  117. TmpFileName=replace(aFiles(lTemp),Server.Mappath(Path)&"\\","")
  118. ExportFileTmpFileName,objStream,objInStream
  119. objInStream.Close
  120. Next
  121. 'Nowaddstufffrommemory
  122. aFiles=objMemoryFiles.Keys
  123. ForlTemp=0toUBound(aFiles)
  124. objInStream.Open
  125. objInStream.WriteTextobjMemoryFiles.Item(aFiles(lTemp))
  126. objInStream.Position=0
  127. ExportFileaFiles(lTemp),objStream,objInStream
  128. objInStream.Close
  129. Next
  130. objStream.WriteTextString(BlockSize,Chr(0))
  131. 'Rewindthestream
  132. 'Remembertochangethetypebacktobinary,otherwisethewritewilltruncate
  133. 'pastthefirstzerobytecharacter.
  134. objStream.Position=0
  135. objStream.Type=1
  136. 'Setallthebrowserstuff
  137. Response.AddHeader"Content-Disposition","filename="&TarFilename
  138. Response.ContentType="application/x-tar"
  139. Response.BinaryWriteobjStream.Read
  140. 'Closeitandgohome
  141. objStream.Close
  142. SetobjStream=Nothing
  143. SetobjInStream=Nothing
  144. EndSub
  145. 'Buildaheaderforeachfileandsendthefilecontents
  146. PrivateSubExportFile(sFilename,objOutStream,objInStream)
  147. DimlStart,lSum,lTemp
  148. lStart=objOutStream.Position'Recordwhereweareupto
  149. IfIgnorePathsThen
  150. 'Weignoreanypathsprefixedtoourfilenames
  151. lTemp=InStrRev(sFilename,"\\")
  152. iflTemp<>0then
  153. sFilename=Right(sFilename,Len(sFilename)-lTemp)
  154. endif
  155. sFilename=BasePath&sFilename
  156. EndIf
  157. 'Buildtheheader,everythingisASCIIinoctalexceptforthedata
  158. objOutStream.WriteTextLeft(sFilename&String(100,Chr(0)),100)
  159. objOutStream.WriteText"100"&Right("000"&Oct(Permissions),3)&""&Chr(0)'Filemode
  160. objOutStream.WriteTextRight(String(6,"")&CStr(UserID),6)&""&Chr(0)'uid
  161. objOutStream.WriteTextRight(String(6,"")&CStr(GroupID),6)&""&Chr(0)'gid
  162. objOutStream.WriteTextRight(String(11,"0")&Oct(objInStream.Size),11)&Chr(0)'size
  163. objOutStream.WriteTextRight(String(11,"0")&Oct(dateDiff("s","1/1/197010:00",now())),11)&Chr(0)'mtime(Numberofsecondssince10amonthe1stJanuary1970(10amcorrect?)
  164. objOutStream.WriteText"0"&String(100,Chr(0))'chksum,typeflagandlinkname,writeoutallblankssothattheactualchecksumwillgetcalculatedcorrectly
  165. objOutStream.WriteText"ustar"&Chr(0)'magicandversion
  166. objOutStream.WriteTextLeft(UserName&String(32,Chr(0)),32)'uname
  167. objOutStream.WriteTextLeft(GroupName&String(32,Chr(0)),32)'gname
  168. objOutStream.WriteText"40"&String(4,Chr(0))'devmajor,devminor
  169. objOutStream.WriteTextString(167,Chr(0))'prefixandleader
  170. objInStream.CopyToobjOutStream'Sendthedatatothestream
  171. if(objInStream.SizeModBlockSize)>0then
  172. objOutStream.WriteTextString(BlockSize-(objInStream.SizeModBlockSize),Chr(0))'Paddingtothenearestblockbyteboundary
  173. endif
  174. 'Calculatethechecksumfortheheader
  175. lSum=0
  176. objOutStream.Position=lStart
  177. ForlTemp=1ToBlockSize
  178. lSum=lSum+(Asc(objOutStream.ReadText(1))And&HFF&)
  179. Next
  180. 'Insertit
  181. objOutStream.Position=lStart+148
  182. objOutStream.WriteTextRight(String(7,"0")&Oct(lSum),7)&Chr(0)
  183. 'Movetotheendofthestream
  184. objOutStream.Position=objOutStream.Size
  185. EndSub
  186. 'Starteverythingoff
  187. PrivateSubClass_Initialize()
  188. SetobjFiles=Server.CreateObject("Scripting.Dictionary")
  189. SetobjMemoryFiles=Server.CreateObject("Scripting.Dictionary")
  190. BlockSize=512
  191. Permissions=438'UNIX666
  192. UserID=0
  193. UserName="root"
  194. GroupID=0
  195. GroupName="root"
  196. IgnorePaths=False
  197. BasePath=""
  198. TarFilename="new.tar"
  199. EndSub
  200. PrivateSubClass_Terminate()
  201. SetobjMemoryFiles=Nothing
  202. SetobjFiles=Nothing
  203. EndSub
  204. EndClass
  205. %>
收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 不用WinRar只有asp将网络空间上的文件打包下载 https://www.kuaiidc.com/69794.html

相关文章

发表评论
暂无评论