Question

We moved from Windows Server 2003 ro Windows Server 2008 and our FileSystemObject script no longer works. Whenever we try to download a file 10-12 Mb it results in a short download, ie: sometimes only getting 15, 19 or 22 Mb of a 26 Mb file.

The server is set to allow downloads of 40+ Mb no problem and this has been confirmed by direct http downloads to the file in root level... tests of direct downloads on 32 Mb are successful 100% of the time. However we need to provide downloads of files that are stored below root, hence we need to use the FSO script.

We have used the script with success for a few years on Windows Server 2003 but lately we cannot get a full download from Windows Server 2008.

strChunkSize = 1024000*1    
strDocFile = "someDocument.doc"
FPath = "C:\data\" & strDocFile
Response.Buffer = True
Response.Clear

Set adoStream = CreateObject("ADODB.Stream") 
adoStream.Open() 
adoStream.Type = 1 

on error resume next

Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fl = fso.GetFile(FPath)
intFilelength = fl.size

adoStream.LoadFromFile(FPath)

Response.AddHeader "Content-Disposition", "attachment; filename=" & fl.name
Response.AddHeader "Content-Length", intFilelength
Response.AddHeader "Accept-Ranges", "bytes"
Response.ContentType = "application/octet-stream"

For i = 0 To adoStream.Size
i = i + strChunkSize
Response.BinaryWrite(adoStream.Read(strChunkSize))
Response.Flush
Next

adoStream.Close
Set adoStream = Nothing 

I have checked out this topic intensively elsewhere and every example of a FSO download script fails, even when using chunks for any file larger than 4 Mb.

Was it helpful?

Solution

The problem in this case was script timeout which by default is only 90 seconds so large files were getting discontinued. To resolve the problem I added some script to set a time out proportional to the download and allowing for slow coaches...

if strDocFileSize <> "" then
strScriptTimeout = (strDocFileSize/1024000)*40
else
strScriptTimeout = 30000
end if

Server.ScriptTimeout = strScriptTimeout
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top