Great ASP Download Script

150 150 rhecht
A lot of people have been asking about this ASP script. Many people are charging for this script when in reality it doesn’t need to be charged. In any case, here’s the script in all its glory:
‘DownloadFile ASP Script
‘Script courtesy of:
On Error Resume Next
‘The following code is optional. The real code is found in “DownloadFile,” a few lines below:
Dim strPath
strPath = CStr(file)
‘– do some basic error checking for the QueryString
If strPath = “” Then
Response.Write(“No file specified.”)
ElseIf InStr(strPath, “..”) > 0 Then
Response.Write(“Illegal folder location.”)
ElseIf Len(strPath) > 1024 Then
Response.Write(“Folder path too long.”)
Call DownloadFile(strPath)
End If
‘This is the script!
Private Sub DownloadFile(file)
‘–declare variables
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream
‘– set absolute file location
strAbsFile = Server.MapPath(file)
‘– create FSO object to check if file exists and get properties
Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)
‘– check to see if the file exists
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
‘– first clear the response, and then set the appropriate headers
‘– the filename you give it will be the one that is shown
‘ to the users by default when they save
Response.AddHeader “Content-Disposition”, “attachment; filename=” & objFile.Name
Response.AddHeader “Content-Length”, objFile.Size
Response.ContentType = “application/octet-stream”
Set objStream = Server.CreateObject(“ADODB.Stream”)
‘– set as binary
objStream.Type = 1
Response.CharSet = “UTF-8”
‘– load into the stream the file
‘– send the stream in the response
do while not (objStream.EOS)
response.BinaryWrite (objStream.Read(1024*256))
Set objStream = Nothing
Set objFile = Nothing
Else ‘objFSO.FileExists(strAbsFile)
Response.Write(“No such file exists.”)
End If
Set objFSO = Nothing
End Sub
It’s simple! Just call “Call Download(whateverfilename)” and you’re good to go!

ASP and downloading files greater than 4 MB

150 150 rhecht

Scenario: You are running a Windows server with IIS, and would like to run a custom script to download a file that may be larger than 4 MB. The file that’s larger than 4 MB  will not download because that’s by default the largest file size in IIS to download. How does one increase the file size?

The following answer was found courtesy of GleamTech:

Open up the file “metabase.xml” with notepad…should be located in C:windowssytem32inetserv. Find the variable named “AspBufferingLimit,” which by default will be 4194304 (or 4 MB’s), and change it to something greater than what is there. By default this is set to around 4 MB’s.

In changing this variable you are increasing the max size of ASP response buffer, thus letting you download files greater than 4 MB’s using “WexFree.”

To upload files greater than this ammount, look for the variable named “AspMaxRequestEntityAllowed” and change it to the desired size. And voila! By increasing the number of these variables, you can control the size of uploads and downloads (respectively).