473,378 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 14546
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Hüseyin DEMİRAĞ | last post by:
Hi all, I think that I should ask the question like that. I want to run MySQL on 14 client. What am I do. I try but There is a problem that i can't find... Please help me. Hüseyin DEMİRAĞ...
0
by: durumdara | last post by:
Hi ! I have some backup files on a server farm. I want to store these local backup files on a backup file server for "safety's snake". These files are compressed zip files with 12 character...
1
by: Green | last post by:
Hi, I had a question about how to copy files from server to server on the same LAN. Basically, i need to copy files from "develope server" to the "test server", then eventually to the "production...
3
by: Iwan Petrow | last post by:
Hi I have a Web application. How could I copy a file from one path on the client machine to another path on the client machine? Thanks.
8
by: Chris Strobel | last post by:
I have 2 web servers where I need to write a PDF file and need to keep them in sync. In others words, If the Server1 is getting called to create the PDF, then it needs to copy the PDF to the other...
2
by: 1388-2/HB | last post by:
On a W2K3 box running IIS 6 I have a web app that implements Forms Authentication mixed with AD (the login page autheticates users against AD & impersonates them with each page request). This...
8
by: Paw | last post by:
Greetings. I use asp. what I need is is when a visitor comes to the site, I need it to check the host name. if "www.hometowndigest.com" is the host, then check a folder named "something" and if...
2
by: PulkitZery | last post by:
Hi I am working on a project and what i need to do is to transfer video files (big in size, >100MB) from client PC to my server. On my server I have WebService running to communicate with my Client...
0
by: sivaramsekar | last post by:
Hi, I have a requirement to copy files (images) from a different server to our web server which has IIS 6.0 and asp.net 3.5. When i try it in my local dev machine i am able to copy and save...
2
by: parmarjm | last post by:
Hi I am trying to copy files from mapped drive (J:\) to a different machine. The perl script is going to run on my machine to copy files from one place to another. File transfer works when i copy...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.