Solved

write file to remote machine

Posted on 2011-09-19
6
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Title # Comments Views Activity
tomcat startup error 5 134
ejb stateless example 2 40
Desingning Refactoring existing code 2 31
Java 8 to Java 6 8 32
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

740 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