private Result scp(String privateKeyPath, String from, String to, int port) { File tmpHostsFile = null; try { from = escapeSshPathIfNecessary(from); to = escapeSshPathIfNecessary(to); tmpHostsFile = File.createTempFile("known-hosts", "throwaway"); Result r = sh.run( scpPath + " -i " + privateKeyPath + " -o StrictHostKeyChecking=no" + " -o UserKnownHostsFile=" + tmpHostsFile.getAbsolutePath() + " -P " + port + " " + from + " " + to); if (r.getExitCode() != 0) { throw new ShellException(r); } return r; } catch (IOException e) { throw new RuntimeException(e); } finally { if (tmpHostsFile != null) tmpHostsFile.delete(); } }