?
Solved

write file to remote machine

Posted on 2011-09-19
6
Medium Priority
?
271 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

770 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