P
PeterB
Hi!
I am using the script below to download files, that are in a non-public
directory, from my site. The "smaller files" section works for smaller
files. However when the files are getting larger, it won't work! I'm not
sure what the size limit is, or if it is some kind of timeout, which would
mean very small files if the connection is slow (I'm working against a
server on the LAN).
When I try to download larger files with the "small file"-section, I only
get a fraction (a few bytes) of the file. The "Large files"-section however
transmitts the file correctly except for a FEW bytes. My testfile is
16.010.423bytes originally, but downloaded it is 16.009.507 bytes.
As I am explicitly setting the size of the file in the download I cannot
understand why this happens?!?
Server: Win 2003, IIS 6.0
Client: WinXP SP2
The code below is partially taken from this page:
http://www.aspfaq.com/show.asp?id=2161
First fFileName and fFullPath is set...
if fs.FileExists(fFullPath)=false then
Set fs=Nothing
Response.End
Else
Set objFileStream = fs.GetFile(fFullPath)
intFileLength = objFileStream.Size 'Size of file
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open
adoStream.Type = 1 'Binary
adoStream.LoadFromFile(fFullPath)
'----------------- Larger files ------------------
If intFileLength > 2000000 Then '~2MB size limit
Response.Buffer = False
Server.ScriptTimeout = 30000
chunk = 2048
iSz = adoStream.Size
Response.ContentType = "octet-stream" '"application/zip"
Response.AddHeader "Content-Disposition", "attachment; filename=" &
fFileName
Response.AddHeader "Content-Length", iSz
For i = 1 To iSz \ chunk
If Not Response.IsClientConnected Then Exit For
Response.BinaryWrite adoStream.Read(chunk)
Next
If iSz Mod chunk > 0 Then
If Response.IsClientConnected Then
Response.BinaryWrite objStream.Read(iSz Mod chunk)
End If
End If
adoStream.Close
Set adoStream = Nothing
'------------------- Smaller files -----------------
Else
Response.Buffer = True
Server.ScriptTimeout = 30000
Response.Clear
Response.ContentType = "octet-stream"
Response.AddHeader "Content-Disposition","attachment; filename=" &
fFileName
Response.AddHeader "Content-Length", intFileLength
Response.BinaryWrite(adoStream.Read(intFileLength))
Response.Flush
adoStream.Close
Set adoStream = Nothing
Set objFileStream = Nothing
Set fs = Nothing
End If
End If
Response.End
I am using the script below to download files, that are in a non-public
directory, from my site. The "smaller files" section works for smaller
files. However when the files are getting larger, it won't work! I'm not
sure what the size limit is, or if it is some kind of timeout, which would
mean very small files if the connection is slow (I'm working against a
server on the LAN).
When I try to download larger files with the "small file"-section, I only
get a fraction (a few bytes) of the file. The "Large files"-section however
transmitts the file correctly except for a FEW bytes. My testfile is
16.010.423bytes originally, but downloaded it is 16.009.507 bytes.
As I am explicitly setting the size of the file in the download I cannot
understand why this happens?!?
Server: Win 2003, IIS 6.0
Client: WinXP SP2
The code below is partially taken from this page:
http://www.aspfaq.com/show.asp?id=2161
First fFileName and fFullPath is set...
if fs.FileExists(fFullPath)=false then
Set fs=Nothing
Response.End
Else
Set objFileStream = fs.GetFile(fFullPath)
intFileLength = objFileStream.Size 'Size of file
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open
adoStream.Type = 1 'Binary
adoStream.LoadFromFile(fFullPath)
'----------------- Larger files ------------------
If intFileLength > 2000000 Then '~2MB size limit
Response.Buffer = False
Server.ScriptTimeout = 30000
chunk = 2048
iSz = adoStream.Size
Response.ContentType = "octet-stream" '"application/zip"
Response.AddHeader "Content-Disposition", "attachment; filename=" &
fFileName
Response.AddHeader "Content-Length", iSz
For i = 1 To iSz \ chunk
If Not Response.IsClientConnected Then Exit For
Response.BinaryWrite adoStream.Read(chunk)
Next
If iSz Mod chunk > 0 Then
If Response.IsClientConnected Then
Response.BinaryWrite objStream.Read(iSz Mod chunk)
End If
End If
adoStream.Close
Set adoStream = Nothing
'------------------- Smaller files -----------------
Else
Response.Buffer = True
Server.ScriptTimeout = 30000
Response.Clear
Response.ContentType = "octet-stream"
Response.AddHeader "Content-Disposition","attachment; filename=" &
fFileName
Response.AddHeader "Content-Length", intFileLength
Response.BinaryWrite(adoStream.Read(intFileLength))
Response.Flush
adoStream.Close
Set adoStream = Nothing
Set objFileStream = Nothing
Set fs = Nothing
End If
End If
Response.End