Hi,
I am trying to execute a copy command using Apache Commons Exec API. Below
is my effort :
String initialCommand = "scp -i";
String privateKey = "/Users/TD/.ssh/id_rsa";
String currentFile = "/Users/TD/One.txt";
String target = "[email protected]:";
// Space is present in destination
String destination="/Leo/Ta/San Diego";
destination=destination.replaceAll(" ", "\\\\ ");
String completeCommand = initialCommand + " " + privateKey + " " +
currentFile + " " + target + destination;
System.out.println(completeCommand);
CommandLine commandLine = new CommandLine(completeCommand);
System.out.println(commandLine.toString());
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(0);
executor.execute(commandLine);
Output :
> scp -i /Users/TD/.ssh/id_rsa /Users/TD/One.txt [email protected]:/Leo/Ta/San\
Diego
> scp -i /Users/TD/.ssh/id_rsa /Users/TD/One.txt [email protected]:/Leo/Ta/San/
Diego
I am noticing that backslash is getting updated and also my command is not
running with error "No such file or directory".
I am new to this library. Any suggestion would be appreciated.