Solved

write file to remote machine

Posted on 2011-09-19
6
264 Views
Last Modified: 2012-06-21
my java code is sitting on application server, I need to write the file to web server which is on different machine (remote), how can I do that? I can write to local machine using FileOutputStream.
0
Comment
Question by:xiaoyunwu
  • 3
  • 2
6 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36560675
You can't write directly, unless
you can map the folder on one machine to another machine


Alternatively you may set up RMI server (Remote Method invocatiuon) servere and you can pass data to that serever
and on that server process write a file

RMI server is a very lightweight serever and pretty simple to do:
http://download.oracle.com/javase/tutorial/rmi/index.html
0
 

Author Comment

by:xiaoyunwu
ID: 36561191
I'm trying to use the following, but does not seem to work. Not sure why.

URL url = new URL(args[0]);
      URLConnection connection = url.openConnection();
      connection.setDoOutput(true);

      OutputStreamWriter out = new OutputStreamWriter(
                              connection.getOutputStream());
      out.write("string=" + stringToReverse);
      out.close();

http://download.oracle.com/javase/tutorial/networking/urls/readingWriting.html
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36561295
I don't think it would wotk tyhis way - unless you have specific web page which would be accepting
your file.
Web server by its normal  nature is desdigned to serve the page to the client not vice versa,
unless you invent some active page there will not just accpet file form you

You can send some sdata in the fornm of POST and then some serv;et on that sude coud accept it and wrote it to the file
But you'll need some servlet and it means some engine on that side, like Tomcat.

Maybe you can salos sod somethinglike that with PHP or cgi - but you need special activity on the side of the sever,
not just http serevr running there
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 47

Expert Comment

by:for_yan
ID: 36561332


Look here in the section "Writing to URL connection" (but you need servlet running ion that server side, noty just webserver):
http://download.oracle.com/javase/tutorial/networking/urls/readingWriting.html
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 36561383
It's not really a Java problem - although you may want to implement it in Java.

Think of implementing it outside java and you will solve the problem. If the remote machine is not on your LAN/WAN then your best bet is to use a technology that's designed for the transfer of files, i.e. ftp - preferably in one of its secure forms
0
 

Author Closing Comment

by:xiaoyunwu
ID: 36570205
I was using itext to create pdf file, then writing to a file.
Instead I should use: response.getOutputStream.
http://viralpatel.net/blogs/2009/04/generate-pdf-file-in-java-using-itext-jar.html
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now