Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to file on another server

Status
Not open for further replies.

gregmosu

Programmer
Jul 8, 2002
117
US
How do I write to a file that resides on another server? I've tried it with both a Socket and a URL.. I can read the text file without problems, but I cant write to it..
(I have already checked permisions)

So far, this was my latest attemp:

String data="Write this to file!";
URL myURL = new URL("URLConnection con = myURL.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-type", "text/plain");
con.setRequestProperty("Content-length", data.length()+"");

PrintStream out = new PrintStream(con.getOutputStream());
out.print(data);
out.flush();
out.close();



Any suggestions that could at least point me in the right direction would be helpfull.

Thanks,
Greg
 
>> How do I write to a file that resides on another server?

By having code that executes on the "other server".
or
Having a "mapped" drive so it appears as a "local" disk to the host server.

Is that what you mean?

-pete
 
Well, I can do it by having simple script sitting on the other server waiting for commands, but I found the example I posted above on the web somewhere.. and the author claimed you could append data to the file sitting on another server using that method.. but I cant get it to work.
 
That makes no sense to me, but maybe i'm an idiot, I have been before and will be again to be sure LOL

-pete
 
It doesnt make sense to me either. The example sure didnt work.. but since I dont deal with file i/o that much, I thought I'd post it and see if I was missing something.

Thanks,
Greg
 
I agree with pete..the simplest solution is to map the drive.

However if that can't for whatever reason be done...maybe try to FTP the file once you are done writing it. Then the other server can listen for new files and moves it to the correct folder...

Another solution could be to use RMI...

 
Referring to your original method, the API for URLConnection certainly says it's possible to both read AND write. Is there some sort of application server listening on the other machine - something that the socket connects to? What problems were you experiencing? Were you getting a specific exception? "When you have eliminated the impossible, whatever remains, however
improbable, must be the truth." ~ Arthur Conan Doyle
 
>> the API for URLConnection certainly says it's possible
>> to both read AND write.

yes but the writing is to the connection not to the file system on the remote machine reading from the connection.

you need the code that is reading the connection to do the writing to the file system for you, like an FTP server or a server of your own making, etc. A web server certainly should not do it for you when pointed to a text file:

>> new URL("
-pete
 
No, not getting exceptions.. not getting any errors at all. Originally, I was going to write a simple app. listening for the connection, but I found this example on the web, and it looked like you could do it without having a simple sort of TCP server listing. It really not a big deal that it doesnt work, I was currious to see what everyone thought. Thanks for all your help so far.

-Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top