Meaningless Drivel is fun!*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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
Author

Copy file from Windows to remote Unix Server

Megan Schanks
Greenhorn

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 "test.web.mycompany.com:/data/testRuntime rt"

String cmd = "rcp -pw password C:\\Tomcat 5.5\\webapps\\MyProject\\input.txt test.web.mycompany.com:/data/test

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
Bartender

Joined: Mar 07, 2007
Posts: 1280

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.

Marco
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Copy file from Windows to remote Unix Server