Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old May 23rd, 2006, 08:55 PM
zerbie45@gmail.com
Guest
 
Posts: n/a
Default 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.

  #2  
Old May 23rd, 2006, 09:25 PM
Bob Barrows [MVP]
Guest
 
Posts: n/a
Default Re: how to copy files from web server to client

zerbie45@gmail.com wrote:[color=blue]
> 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.
>[/color]
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.


  #3  
Old May 24th, 2006, 11:45 AM
SEOSpecialist
Guest
 
Posts: n/a
Default Re: how to copy files from web server to client

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")))

%>

  #4  
Old May 24th, 2006, 12:15 PM
Bob Barrows [MVP]
Guest
 
Posts: n/a
Default Re: how to copy files from web server to client

SEOSpecialist wrote:[color=blue]
> Hi Bob.... think you misunderstood zerbi's question because he does
> indeed want it to be user initiated.[/color]

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"


  #5  
Old May 24th, 2006, 01:35 PM
SEOSpecialist
Guest
 
Posts: n/a
Default Re: how to copy files from web server to client

It is this:-[color=blue][color=green]
>> I want a page with a link that when pressed....[/color][/color]

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

  #6  
Old May 27th, 2006, 05:45 PM
vicky
Guest
 
Posts: n/a
Default Re: how to copy files from web server to client

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

  #7  
Old May 27th, 2006, 06:35 PM
Evertjan.
Guest
 
Posts: n/a
Default Re: how to copy files from web server to client

vicky wrote on 27 mei 2006 in microsoft.public.inetserver.asp.general:[color=blue]
> 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.[/color]

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)
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.