File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Copy file from Windows to remote Unix Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Copy file from Windows to remote Unix Server" Watch "Copy file from Windows to remote Unix Server" New topic

Copy file from Windows to remote Unix Server

Megan Schanks

Joined: Feb 06, 2004
Posts: 3
I have a Java application (web) that creates a text file. I need to copy that text file to a remote Unix server. Can anyone tell me if I am on the right track with the following code? I'm not sure if my Unix syntax is right.

//Password is "test"
//Local directory is "C:\\Tomcat 5.5\\webapps\\MyProject\\input.txt
//Remote directory is " rt"

String cmd = "rcp -pw password C:\\Tomcat 5.5\\webapps\\MyProject\\input.txt

Runtime rt = Runtime.getRuntime();
Process p= rt.exec(cmd);

BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

Help is appreciated!
Marco Ehrentreich
best scout

Joined: Mar 07, 2007
Posts: 1294

Hi Megan,

a good solution depends much on your requirements. What about transfer speed? Security? The network topology (subnets, routers, firewalls etc.)?

Your idea is surely a good starting point. Generally running the UNIX service for "rcp" should be regarded as unsafe because the password is transfered in plain text and anybody could sniff it to manipulate or destroy the data. As I said it depends on your requirements if this is really an issue but you should at least be aware of this as potential security problem.

Besides your planned solution there are many alternative scenarios which also have their strengths and weaknesses. Some other ideas which come quickly to mind are RMI, FTP transfer without special Java code, a shared NFS or SMB network filesystem, a pure Java socket connection without the "rcp" service and many more.

I'd suggest to try your own solution and think about alternatives if you have problems or you aren't really lucky with it.

I agree. Here's the link:
subject: Copy file from Windows to remote Unix Server
It's not a secret anymore!