Rsync runs from java returns with file error not found

I try to execute the rsync command (local atm testing) using the Apache Commons Exec library, and I get an error, and the execution of the same command in the terminal does not cause problems.

This is the command I would like to execute:

rsync -zve "ssh -i /home/user/.ssh/testkey" /home/user/playground/src/HNI_0084.JPG user@localhost :/home/user/playground/dst 

And this is the error message I get when I execute a command in my Java class:

 rsync: Failed to exec ssh -i /home/user/.ssh/testkey: No such file or directory (2) rsync error: error in IPC code (code 14) at pipe.c(84) [sender=3.0.9] rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: error in IPC code (code 14) at io.c(605) [sender=3.0.9] org.apache.commons.exec.ExecuteException: Process exited with an error: 14 (Exit value: 14) at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377) at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160) at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147) at LocalExecutor.execute(LocalExecutor.java:21) 

So this is my java class for executing local commands:

 import java.io.IOException; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.ExecuteWatchdog; public class LocalExecutor { public int execute(String command, String[] args) { CommandLine cl = new CommandLine(command); cl.addArguments(args); System.out.println(cl.toString()); DefaultExecutor executor = new DefaultExecutor(); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = 0; try { exitValue = executor.execute(cl); } catch (IOException e) { e.printStackTrace(); } return exitValue; } } 

And finally, the array of arguments passed to the program is as follows:

 {-zve, ssh -i /home/user/.ssh/testkey, /home/user/playground/src/HNI_0084.JPG, user@localhost :/home/user/playground/dst/} 

It is completely unknown why rsync will complain about the call, since quoting arguments containing spaces is handled by the library, and the actual rsync call should look exactly like the line I posted above.

Any ideas?: /

+4
source share
1 answer

It is possible that rsync does not find ssh when executed from your java code. Try using the full path to ssh exectable rather than just passing a command.

0
source

Source: https://habr.com/ru/post/1481246/


All Articles