• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Copy file from Windows to remote Unix Server

 
Megan Schanks
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic