Solved

write file to remote machine

Posted on 2011-09-19
6
267 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

840 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