0

I want to write a java code that executes Linux command to copy a directory from server to another server.I got a directory which contains sub directories and files. So I need to copy all these contents to another server. How can I use Linux command for that purpose in java.

Thanks a lot!

hKs
  • 478
  • 1
  • 6
  • 20

1 Answers1

1

You could look at these good post's here

The only thing that would change is command. there user was asking for diff, here you are asking to copy between two machines. I am assuming you could do passwordless ssh from your source machine to destination and if that's the case you could use scp command to copy the directory like below:

scp -r /home/test/blah imauser@thathost:/home/test/destination/directory

-r will recursively copy directories as well to your existing directory as above on thathost.

Community
  • 1
  • 1
SMA
  • 35,277
  • 7
  • 46
  • 71