I am trying to copy a file via ssh from remote server to client. When executing my command on cli, the file is being copied to the correct location. But if I am executing the exactly same command via Java, the file is being copied to the remote machines directory instead of the clients one.
This is the command I am using (I am using a key s.t. no password has to be entered):
ssh -i /home/user/.ssh/id_rsa -C -p 2201 test@localhost 'cat /opt/test/file.txt' > /home/user/file.txt
And this is the code, quite simple:
Process p;
p = Runtime.getRuntime().exec("ssh -i /home/user/.ssh/id_rsa -C -p 2201 test@localhost 'cat /opt/test/file.txt' > /home/user/file.txt");
Any idea why the file is being copied to the wrong machines directory and how to get it copied to the clients directory instead, when executing the command using java?