Forum Moderators: open

Message Too Old, No Replies

Prevent direct file download ASP legacy

Is there a way?

         

NLConsulting

7:04 pm on Oct 11, 2006 (gmt 0)

10+ Year Member



I've been strugggling with this for a few days now. I have a restricted section setup that requires a username/password to access (SQL db using legacy ASP) of which there are many u/p's. I have a few self-extracting zip files located within this protected area that I also want to be able to lock-down and not allow direct access to, essentially having a download.asp scripted page that streams the file to the browser upon successful authentication. The problem is that I cannot get it to work properly with ZIP files (it has worked with a JPG) and I can't find any information on if this is even possible with legacy ASP. I have found a ton of information on using Server.WriteFile, but that only works for ASP.NET.

I've tried the code below in various fashions, from changing the ContentType to octet-stream, to using text (ascii) instead of binary (which in case you're wondering downloads the script file, not the attachment file, then crashes IE). In the end, the files will all be protected in a non-web accessible directory with the filename being passed into the script via the URL or a post/get (not sure which yet). The example below that I've been testing with just calls upon a file located in the same directory as the script.

<%
Response.ContentType = "application/zip"
Response.AddHeader "Content-disposition","attachment;filename=myfile.exe"

Dim strFilePath

strFilePath = Server.MapPath("myfile.exe")
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1 '1=binary 2=text
objStream.LoadFromFile strFilePath

Response.BinaryWrite objStream.Read

objStream.Close
Set objStream = Nothing
%>

I need some help. Any legacy ASP guru's out there?

Brad_H

8:06 pm on Oct 12, 2006 (gmt 0)

10+ Year Member



I always use "application/octet-stream" for this. Here is some sample code that works for me:


<%
Dim strFileName
strFileName = "t.zip"

Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-disposition","attachment;filename=" & strFileName

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1 '1=binary 2=text
objStream.LoadFromFile Server.MapPath(strFileName)

Response.BinaryWrite objStream.Read

objStream.Close
Set objStream = Nothing
%>

NLConsulting

4:15 pm on Oct 13, 2006 (gmt 0)

10+ Year Member



Well, that works fine for normal files, however it does not for work for self-extracting zip files (.exe). If you transmit the file via octet-stream, Windows treats the downloaded exe file as a standard Win32 executable, not a ZIP archive. Furthermore, if you use application/zip or any variant of zip (x-zip, compressed, etc) it is not recognized as a zip file by WinZip once it is downloaded.

I am pulling hair out...