File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Read and write files from a remote server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Read and write files from a remote server" Watch "Read and write files from a remote server" New topic
Author

Read and write files from a remote server

joseph corner
Ranch Hand

Joined: Feb 20, 2004
Posts: 50
Hi all,
I have a servlet/jsp forum application which supports image upload. For storage space reasons, I would like to write the uploaded images to a different server than the one hosting my web app. Obviously I will also need to read the image data from there.

I am having difficulties sorting out my file permissions - if I fix this will I be able to read and write to absolute file URLs? Or is it more complicated than that... ?

Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41839
    
  63
If the remote file system is mounted via NFS it should work just like it would locally, assuming all permissions are set appropriately. If the remote file system is accessed via SMB it gets a bit more complicated.
[ August 21, 2006: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
joseph corner
Ranch Hand

Joined: Feb 20, 2004
Posts: 50
Hi,
Do I really need to mount the remote file system?
Is this a basic security feature of java, that it can't write to a folder on a remote web server?

My case is complicated by the fact that my web app is a plugin in a larger application, and I don't have direct access to the web server which runs it. So I'd prefer not to have to set up mounted file systems.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by joseph corner:

Do I really need to mount the remote file system?
Is this a basic security feature of java, that it can't write to a folder on a remote web server?


Java can't magically reach into other machines to read and write to their file systems. There has to be some mechanism in place for it to do so.
A possible alternative is to set up a service on the remote system that does the reading and writing for you.
This could be a web service, FTP server, webdav server, etc...


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
joseph corner
Ranch Hand

Joined: Feb 20, 2004
Posts: 50
Hi,
I have ftp running on the remote server, and I could also run a servlet there to read and write the images.
What would people's best solution be, in terms of efficiency and speed?
My first experiments with ftping from my servlet have been unsuccessful....
Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41839
    
  63
I'd say go with ftp (instead of something HTTP-based). What problems did you encounter using FTP from within a servlet? Using Jakarta Commons Net I had no issues last time I did it (although it ran in a separate thread, not the servlet itself).
joseph corner
Ranch Hand

Joined: Feb 20, 2004
Posts: 50
I tried some basic ftp transactions using com.fooware.net.
The application just hung when trying to connect - no error message. I'll try it again from a stand alone java app., and will take a look at jakarta commons net too..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read and write files from a remote server