Solved

write file to remote machine

Posted on 2011-09-19
6
266 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reverse digits of a number using for loop 5 40
Windows 10 IE Certificate Issue 10 45
servlet filter example 37 58
null output 3 24
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…
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 about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

816 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

10 Experts available now in Live!

Get 1:1 Help Now