469,352 Members | 2,154 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

how to copy files from web server to client

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.

May 23 '06 #1
6 14203
ze******@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.
May 23 '06 #2
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")))

%>

May 24 '06 #3
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"
May 24 '06 #4
It is this:-
I want a page with a link that when pressed....


..... 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

May 24 '06 #5
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

May 27 '06 #6
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)
May 27 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Hüseyin DEMİRAĞ | last post: by
reply views Thread by durumdara | last post: by
3 posts views Thread by Iwan Petrow | last post: by
8 posts views Thread by Chris Strobel | last post: by
2 posts views Thread by 1388-2/HB | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.