Do not winrar to download files on the network space

Source: Internet
Author: User
Tags chr end header include insert string version
winrar| Package | network | download

This method, does not recommend compression, large files,

General small file pressure a few still very useful

<%@ Language=vbscript%>
<% Option Explicit%>
<!--#include file= "asptar.asp"-->
<%
Response.Buffer = True
Response.Clear
Dim Co,temp,t,x,i,fsobrowse,thefolder,thesubfolders,filepath,s,ph,objtar
Co=0
Ph= "./upfile" ' File path ' compresses all files under Upfile
Set Objtar = New tarball
Objtar.tarfilename= "Lvbbs_updatefile.rar" ' packaged name
Objtar.path=ph
Set Fsobrowse=createobject ("Scripting.FileSystemObject")
Set Thefolder=fsobrowse.getfolder (Server.MapPath (PH))
Set thesubfolders=thefolder.subfolders
For each T in Thefolder.files
temp= Temp & t.name & "|"
Co=co+1
Next
For each x in Thesubfolders
For all I in X.files
temp= Temp & x.name& "/" &i.Name& "|"
Co=co+1
Next
Next
If co<1 Then
Response.Write "No updatable file downloads available"
' Objtar.addmemoryfile ' Sorry.txt ', ' not file! '
Else
Temp=left (Temp,len (Temp)-1)
Filepath=split (Temp, "|")
For S=0 to Ubound (FilePath)
Objtar.addfile Server.MapPath (ph& "/" &filepath (s))
Next
If response.isclientconnected Then
Objtar.writetar
Response.Flush
End If
End If
Set Objtar = Nothing
Set fsobrowse= Nothing
Set Thefolder = Nothing
Set thesubfolders = Nothing

%>

Asptar.asp

<%
' UNIX Tarball Creator
' ====================
' Author:chris Read
' version:1.0.1
' ====================
' Homepage:http://users.bigpond.net.au/mrjolly/
'
' This class provides the ability to archive multiple files together into a single
' distributable file called a tarball (the TAR actually stands for Tape ARchive).
' These are common UNIX files which contain uncompressed data.
'
' So what are this useful for? So, it allows to effectively combine multiple
' Files into a single file for downloading. The TAR files are readable and extractable
' By a wide variety of tools, including the very widely distributed.
'
' This script can include two types of the data in each archive, the file data read from a disk,
' and also things direct from memory, like from a string. The Archives support files in
' A binary structure, so your can store executable files if you need to, or just store
' Text.
'
' This class is developed to assist me with a few projects and has grown with every
' implementation. Currently I use this class to tarball the XML data for archival purposes
' which allows me to grab ' of the dynamically created XML files in a single download.
'
' There are a small number of properties and methods, which are, outlined in the
' accompanying documentation.
'
Class Tarball
Public tarfilename ' resultant tarball filename

Public UserID ' UNIX user ID
Public UserName ' UNIX user name
Public GroupID ' UNIX Group ID
Public groupname ' UNIX Group name

Public Permissions ' UNIX Permissions

Public BlockSize ' blocks byte for the tarball (default=512)

Public ignorepaths ' Ignore any supplied paths for the tarball output
Public BasePath ' Insert a base path and each file
Public Path

' Storage for file information
Private Objfiles,tmpfilename
Private Objmemoryfiles

' File list management subs, very basic stuff
Public Sub AddFile (sfilename)
Objfiles.add Sfilename,sfilename
End Sub

Public Sub RemoveFile (sfilename)
Objfiles.remove sFileName
End Sub

Public Sub addmemoryfile (sfilename,scontents)
Objmemoryfiles.add sfilename,scontents
End Sub

Public Sub removememoryfile (sfilename)
Objmemoryfiles.remove sFileName
End Sub

' Send the tarball to the browser
Public Sub Writetar ()
Dim objstream, Objinstream, Ltemp, Afiles

Set objstream = Server.CreateObject ("ADODB. Stream ")" The main stream
Set Objinstream = Server.CreateObject ("ADODB. Stream ")" the input stream for data

objStream.Type = 2
Objstream.charset = "X-ansi" ' Good old extended ASCII
objStream.Open

Objinstream.type = 2
Objinstream.charset = "X-ansi"

   ' Go through all files stored on disk a   afiles = Objfiles.items
  
& Nbsp; for ltemp = 0 to UBound (afiles)
   objinstream.open
   objinstream.loadfromfile Afiles (ltemp)
   objinstream.position = 0
   ' exportfile afiles (ltemp), objstream, Objinstream
             tmpfilename =replace ( Afiles (Ltemp), Server.MapPath (Path) & "\" "" ")
    exportfile Tmpfilename,objstream, Objinstream
   objinstream.close
  next

' Now add stuff from memory
Afiles = Objmemoryfiles.keys

For ltemp = 0 to UBound (afiles)
Objinstream.open
Objinstream.writetext Objmemoryfiles.item (Afiles (ltemp))
objinstream.position = 0
Exportfile Afiles (ltemp), Objstream,objinstream
Objinstream.close
Next

Objstream.writetext String (BLOCKSIZE,CHR (0))

' Rewind the Stream
' Remember to-change the type back to binary, otherwise the write'll truncate
' Past the ' the ' character.
objstream.position = 0
objStream.Type = 1
' Set all ' browser stuff
Response.AddHeader "Content-disposition", "Filename=" & Tarfilename
Response.ContentType = "Application/x-tar"
Response.BinaryWrite Objstream.read

' Close it and go home
objStream.Close
Set objstream = Nothing
Set Objinstream = Nothing
End Sub

' Build a header to each file and send the file contents
Private Sub exportfile (Sfilename,objoutstream,objinstream)
Dim Lstart, Lsum, ltemp

Lstart = Objoutstream.position ' record where we are are up to

If ignorepaths Then
' We ignore any paths prefixed into our filenames
Ltemp = InStrRev (sfilename, "\")
If ltemp <> 0 Then
sFileName = Right (Sfilename,len (sfilename)-ltemp)
End If
sFileName = BasePath & sFileName
End If

' Build the header, everything are ASCII in octal except for the ' data
Objoutstream.writetext Left (sFileName & String (100,CHR (0)), 100)
Objoutstream.writetext "M" & Right ("+" & Oct (Permissions), 3) & "& Chr (0) ' File mode
Objoutstream.writetext Right (String (6, "") & CStr (UserID), 6) & "" & Chr (0) ' UID
Objoutstream.writetext Right (String (6, "") & CStr (GroupID), 6) & "" & Chr (0) ' gid
Objoutstream.writetext Right (String (one, "0") & Oct (objinstream.size), one) & Chr (0) ' Size
Objoutstream.writetext Right (String, "0") & Oct (DateDiff ("s", "1/1/1970 10:00", Now ()), one) & Chr (0) ' Mtime ( Number of seconds since 10am on the 1st January 1970 (10am correct?)
Objoutstream.writetext "0" & String (100,CHR (0)) ' Chksum, type flag and link name, write out all blanks so The actual checksum'll get calculated correctly
Objoutstream.writetext "Ustar" & Chr (0) ' Magic and version
Objoutstream.writetext Left (UserName & String (32,CHR (0)) ' uname
Objoutstream.writetext Left (GroupName & String (32,CHR (0)) ' Gname
Objoutstream.writetext "& String" (4,CHR (0)) ' Devmajor, Devminor
Objoutstream.writetext String (167,CHR (0)) ' prefix and leader
Objinstream.copyto Objoutstream ' Send the data to the stream

if (objinstream.size Mod BlockSize) > 0 Then
Objoutstream.writetext String (BlockSize-(objinstream.size Mod BlockSize), Chr (0)) ' Padding to the nearest block byte Boun Dary
End If

' Calculate the checksum for the header
Lsum = 0
Objoutstream.position = Lstart

For ltemp = 1 to BlockSize
Lsum = Lsum + (ASC (Objoutstream.readtext (1)) and &HFF&)
Next

' Insert it
Objoutstream.position = Lstart + 148
Objoutstream.writetext Right (String (7, "0") & Oct (Lsum), 7) & CHR (0)

' Move to the ' the ' stream
Objoutstream.position = Objoutstream.size
End Sub

' Start everything off
Private Sub Class_Initialize ()
Set objfiles = Server.CreateObject ("Scripting.Dictionary")
Set objmemoryfiles = Server.CreateObject ("Scripting.Dictionary")

BlockSize = 512
Permissions = 438 ' UNIX 666

UserID = 0
UserName = "root"
GroupID = 0
GroupName = "root"

Ignorepaths = False
BasePath = ""

Tarfilename = "New.tar"
End Sub

Private Sub Class_Terminate ()
Set objmemoryfiles = Nothing
Set objfiles = Nothing
End Sub
End Class
%>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.