Home > Archive > ASP > May 2006 > how to copy files from web server to client
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to copy files from web server to client
|
|
| zerbie45@gmail.com 2006-05-23, 6:56 pm |
| Hi all,
I need to know if, and how, it is possible to use ASP to download a
file automatically from the web server to the client in a given path.
Is that possible ? Ideally I want a page with a link that when pressed
it will copy a certain file that exists on the web server down to the
client.
Any help is appreciated!
Thanks in advance.
| |
| Bob Barrows [MVP] 2006-05-23, 6:56 pm |
| zerbie45@gmail.com wrote:
> Hi all,
>
> I need to know if, and how, it is possible to use ASP to download a
> file automatically from the web server to the client in a given path.
> Is that possible ? Ideally I want a page with a link that when pressed
> it will copy a certain file that exists on the web server down to the
> client.
>
No. This is not possible due to security reasons. All downloads need to
be initiated by the user, and the user gets to pick where the file will
go.
If you are in a WAN, there are other ways to accomplish your goal, which
you can discover by posting to a network administration newsgroup 9I
con't know any offhand - you will need to google for them).
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
| |
| SEOSpecialist 2006-05-24, 7:55 am |
| Hi Bob.... think you misunderstood zerbi's question because he does
indeed want it to be user initiated.
Zerbi, you will need to make use of mime type headers and the
binarywrite method of the response object to 'FORCE' a download.
Save the following code to a file and thn pass along the relative
filename with path via querystring you want to download.
By the way, there is no security checks in place here, so amend
accordingly.
Hope it helps you!
<%
Sub ForceDownload(strFilePath)
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.GetFile(strFilePath)
StrFileSize = oFile.Size
Set oFile = Nothing
Set oFS = Nothing
Const adTypeBinary = 1
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = lcase(Right(strFilePath, 4))
' Feel Free to Add Your Own Content-Types Here
Select Case strFileType
Case ".asf"
ContentType = "video/x-ms-asf"
Case ".avi"
ContentType = "video/avi"
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
Case ".gif"
ContentType = "image/gif"
Case ".jpg", "jpeg"
ContentType = "image/jpeg"
Case ".wav"
ContentType = "audio/wav"
Case ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "video/mpeg"
Case ".rtf"
ContentType = "application/rtf"
Case ".htm", "html"
ContentType = "text/html"
Case ".asp"
ContentType = "text/asp"
Case ".pdf"
ContentType = "application/pdf"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select
Response.AddHeader "Content-Disposition", "attachment; filename=" &
StripFileName(StrFilePath)
Response.AddHeader "Content-Length", strFileSize
' In a Perfect World, Your Client would also have UTF-8 as the default
' In Their Browser
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
End Sub
function StripFileName(ByVal asPath)
if asPath = "" Then Exit function
asPath = Replace(asPath, "/", "\")
if InStr(asPath, "\") = 0 Then Exit function
if Right(asPath, 1) = "\" Then Exit function
StripFileName = Right(asPath, Len(asPath) - InStrRev(asPath, "\"))
End function
Call ForceDownload (server.mappath(request.querystring("file")))
%>
| |
| Bob Barrows [MVP] 2006-05-24, 7:55 am |
| SEOSpecialist wrote:
> Hi Bob.... think you misunderstood zerbi's question because he does
> indeed want it to be user initiated.
Why do you say that? He used the word "automatically" and the phrase " ...
to the client in a given path".
However, I hope you are correct and his problem is solved.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
| |
| SEOSpecialist 2006-05-24, 7:55 am |
| It is this:-[color=darkred]
..... that kinda led me to believe it was user initiated. Maybe we are
both misunderstanding his needs.
Since you put it like that, I may be wrong also... lol
| |
|
| Hi there,
It is possible, just create a fso object write the file using this,
give the path and it will be saved to that path directly.
Vivek
| |
| Evertjan. 2006-05-27, 6:55 pm |
| vicky wrote on 27 mei 2006 in microsoft.public.inetserver.asp.general:
> It is possible, just create a fso object write the file using this,
> give the path and it will be saved to that path directly.
Not with standard internet security of the browser.
Yes with a simple wscript on the client,
however that has nothing to do wih ASP.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
|
|
|
|
|