Re: download files with ASP VBScript

From: PeterB (peter_at_data.se)
Date: 02/09/05


Date: Wed, 9 Feb 2005 18:19:44 +0100

I changed to a Win2003 server and the script runs but sometimes I don't get
the entire file! It works sometimes, and especially larger files fail to
download at all or download a small part of the file.

I also had to change the script to be able to handle larger files. But my
main problem now is that the size of the original file and the downloaded
file doesn't match!

The code for larger file download:
Response.Buffer = False
      Server.ScriptTimeout = 30000

    chunk = 2048
      iSz = adoStream.Size

      'Response.ContentType = "application/asp-unknown" ' arbitrary
      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

Any help is appreciated!

Regards,

 Peter

"PeterB" <peter@data.se> skrev i meddelandet
news:uMpBJepDFHA.3492@TK2MSFTNGP12.phx.gbl...
> Hello!
>
> I have some trouble file download, using VBScript. I am using my local IIS
> server (5.1) on my WinXP Pro SP2 machine, could this be an issue?
>
> Are there any fail-safe code snippets that download any files from a
> non-public path?
>
> Here's my script:
>
> <%
> Dim fs, fRelPath, fFileName, fFullPath, arrPath, objFileStream
> set fs=Server.CreateObject("Scripting.FileSystemObject")
>
> sql = "select file_path from files where file_id = " &
> Request.Querystring("id")
> rs.open sql, conn ', adOpenstatic, adLockOptimistic)
>
> fRelPath = rs("file_path")
> arrPath = Split(fRelPath, "\", -1, 1)
> fFileName = arrpath(UBound(arrPath,1)) 'Last object in file array is file
> name
> fFullPath = Server.mappath(fRelPath)
>
> if fs.FileExists(fFullPath)=false then
> response.write("File not found!!<br />")
> response.write("Relative path: " & fRelPath & "<br />")
> response.write("File name: " & fFileName & "<br />")
> response.write("Full path: " & fFullPath & "<br />")
> Set fs=Nothing
> Response.End
> Else
> response.write("File found!!<br>")
> response.write("Relative path: " & fRelPath & "<br />")
> response.write("File name: " & fFileName & "<br />")
> response.write("Full path: " & fFullPath & "<br />")
> end If
>
> Set objFileStream = fs.GetFile(fFullPath)
> intFilelength = objFileStream.size 'Size of file
>
> ***** I Don't get to this line.... *******
> Response.Write( "Filesize: " & intFilelength & "<br />" )
> 'Response.End
>
> Set adoStream = CreateObject("ADODB.Stream")
> adoStream.Open
> adoStream.Type = 1 'Binary
> adoStream.LoadFromFile(fFullPath)
>
> Response.Clear
> 'Response.ContentType = "application/x-unknown" ' arbitrary
> Response.ContentType = "octet-stream" ' arbitrary
> 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
>
> Response.End
> %>
>
>



Relevant Pages

  • Re: constant runtime errors-please help
    ... Common script errors messages can be eliminated by Clicking: ... click Internet Options. ... Two download versions are available for Windows Script 5.6. ... HiJackThis: - Free ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Idiot proof removal of junk?
    ... | I would like to send everyone a single script or small set of scripts ... | convince windows to boot into safe mode with command prompt. ... FireWall to allow it to download the needed AV vendor related files. ... This will bring up the initial menu of choices and should be executed in Normal Mode. ...
    (microsoft.public.windowsxp.help_and_support)
  • Announcement: Fix management tool for AIX 4.x/5.x available
    ... I'm pleased to announce a tool to automate download and management ... of ".bff" and ".rpm" fix packages for AIX ver. ... "fix-get.sh" script has been designed to automate fix packages ... discovery and download for servers with Unix AIX versions up to 5.3. ...
    (comp.unix.aix)
  • Re: Dynamic loading of javascript files into web pages
    ... after the script has loaded and executed. ... in an external file execute and know that is has loaded? ... the archives, I have shown this MANY times and it was even before ... Want it to download faster? ...
    (comp.lang.javascript)
  • Re: Operations Masters
    ... Run diagnostics against your Active Directory domain. ... Run dcdiag, netdiag and repadmin in verbose mode. ... If you download a gui script I wrote it should be simple to set and run ...
    (microsoft.public.windows.server.active_directory)

Loading