Downloading files with ASP and vbScript

Results 1 to 3 of 3

Thread: Downloading files with ASP and vbScript

  1. #1
    Carolyn Guest

    Default Downloading files with ASP and vbScript

    Can anyone help me. I want to download files from a remote server and save them locally.<BR>I can download them but am not sure how to save them (they are written out at the moment).<BR>Thanks Carolyn<BR>PS. Here is the code so far:<BR><BR>Option Explicit<BR>Response.Buffer = True<BR><BR><BR>Function FileRead(byVal FILE)<BR> &#039; this function reads a file&#039;s contents<BR> Dim strOut : strOut = ""<BR> Dim objFSO, FileDownload<BR> Set ObjFSO = Server.CreateObject("Scripting.FileSystemObject")< BR> Set FileDownload = ObjFSO.OpenTextFile(FILE, 1, False)<BR> strOut = FileDownload.ReadAll()<BR> FileDownload.Close<BR> Set FileDownload = Nothing<BR> Set objFSO = Nothing<BR> FileRead = strOut<BR>End Function<BR><BR><BR>Dim strFileToDownload, strFileContents<BR><BR> &#039; this is the path to the file to be downloaded<BR>strFileToDownload = Request.QueryString("file")<BR><BR> &#039; right now there are no checks on the path...<BR> &#039; anyone could download anything on our server<BR> &#039; but since this is a test, I don&#039;t care...<BR><BR> &#039; pass the path to the function that will read the file<BR>strFileContents = FileRead( strFileToDownload )<BR><BR> &#039; prepare to write everything...<BR>With Response<BR><BR> &#039; add the header with the download file&#039;s name<BR> .AddHeader "Content-Disposition", "filename=" & strFileToDownload<BR><BR> &#039; change the content type from text/html to<BR> &#039; the downloadable one...<BR> .ContentType = "application/octet-stream"<BR><BR> &#039; if you wanted to write something else, you could do it here as well:<BR> .Write "Thanks for downloading this file!" & vbCrLf & vbCrLf<BR><BR> &#039; write the file&#039;s contents which was<BR> &#039; passed from the function above.<BR> .Write strFileContents<BR>End With<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Downloading files with ASP and vbScript

    Dim fso<BR><BR>set fso = Server.CreateObject ("Scripting.FilesystemObject")<BR>dim ts<BR>set ts = fso.opentextfile(filename, ForWriting, true);<BR>ts.Write(strFileContents)<BR><BR>ts.clos e<BR>set ts = nothing<BR>set fso= nothing

  3. #3
    danz Guest

    Default RE: Downloading files with ASP and vbScript

    Carolyn&#039;s code appears to open a file on the server and read it into memory, then your code writes the file back to the server. What&#039;s the point? Where is any "downloading" taking place? I must be missing something...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts