Avatar of vittalmareddy
vittalmareddy
 asked on

Copy a file from server to client machine

Hi
We want to copy a file on server machine to client, user will use browser to request, on process of request it has to copy a file from server specified location to client machine fixed location.
I think this can be achined using apple.

if then how i will open a stream on file which is in server.
server IP : 10.20.30.40  at c:\sample\discloser.pdf
Client IP : 11:22:33:44 at c:\download

JavaWeb Development

Avatar of undefined
Last Comment
vittalmareddy

8/22/2022 - Mon
CEHJ

If it's mounted as a network share, just try the UNC name

http://technojeeves.com/joomla/index.php/free/51-copying-streams
File source = new File("\\\\10.20.30.40\\sharename\\filename");

Open in new window

vittalmareddy

ASKER
How about in case of linux OS.
CEHJ

It would be
File source = new File("//10.20.30.40:/sharename/filename");

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Mick Barry

You don't need to setup network shares just to copy files
Use Runtime.exec() to just run scp command to copy the file.

http://helpdesk.objects.com.au/java/runtime-exec-locks-up
yavathol

Create a simple servlet. In the request pass the location on server. push the contents to the client:

<code>
response.getOutputStream().write(...)
</code>

On client side PC (I guess a webpage is invoked) you will either be prompted where to save a file (no page), or you'll be able to handle the request by saving the contents somewhere (you also provide a page, not only server side).
vittalmareddy

ASKER
This is we don't want, behind the screen it should copy to the client machine, solution we are tyring is.
Applet, which does reading a file from server and write into a new file in client location.
Creating inputstream using File source = new File("\\\\10.20.30.40\\sharename\\filename"); on shared folder in server.
Creating output stream in client machine on fixed location.

siging the applet.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CEHJ

Yes, that should be OK
Mick Barry

the following shows hot to copy a file using java

http://helpdesk.objects.com.au/java/how-do-i-copy-a-file-using-java
vittalmareddy

ASKER
Thanks CEHJ for validation of approach, Objects for suggitions.

above this thread, suggest to map folder sharing, can't we use with out sharing folder in server maching to read file to client machine.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Mick Barry

yes you can as I suggested above. You really don't want to be sharing disks just to copy a file
ASKER CERTIFIED SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
vittalmareddy

ASKER
Thanks for information
CEHJ

:-)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
vittalmareddy

ASKER
As suggested above and the approach i specified above worked for me.
I used using folder sharing.