我正在尝试使用 Apache Commons API 执行复制命令。以下是我的努力:
String privateKey = "/Users/TD/.ssh/id_rsa";
String currentFile = "/Users/TD/One.txt";
String target = "root@my.server.com:";
// Space is present in destination
String destination="/Leo/Ta/San Diego";
CommandLine commandLine = new CommandLine("scp");
commandLine.addArgument("-i");
commandLine.addArgument(privateKey);
commandLine.addArgument(currentFile);
commandLine.addArgument(target + destination);
System.out.println(commandLine.toString());
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(0);
executor.execute(commandLine);
输出 :
scp -i /Users/TD/.ssh/id_rsa /Users/TD/One.txt "root@my.server.com:/Leo/Ta/San Diego"
org.apache.commons.exec.ExecuteException:进程退出并出现错误:1(退出值:1)
相同的程序适用于其中没有空间的目标文件夹:
字符串目的地="/Leo/Ta/SanJose";
scp -i /Users/TD/.ssh/id_rsa /Users/TD/One.txt root@my.server.com:/Leo/Ta/SanJose