### Question:
SSHClient { public void scpFileToRemote(String localFile, String remoteTargetDirectory) throws Exception { FileInputStream fis = null; try { System.out.println("SCP file " + localFile + " to " + remoteTargetDirectory); Session session = newJSchSession(); session.connect(); boolean ptimestamp = false; String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + remoteTargetDirectory; Channel channel = session.openChannel("exec"); ((ChannelExec) channel).setCommand(command); OutputStream out = channel.getOutputStream(); InputStream in = channel.getInputStream(); channel.connect(); if (checkAck(in) != 0) { System.exit(0); } File _lfile = new File(localFile); if (ptimestamp) { command = "T " + (_lfile.lastModified() / 1000) + " 0"; command += (" " + (_lfile.lastModified() / 1000) + " 0\n"); out.write(command.getBytes()); out.flush(); if (checkAck(in) != 0) { throw new Exception("Error in checkAck()"); } } long filesize = _lfile.length(); command = "C0644 " + filesize + " "; if (localFile.lastIndexOf("/") > 0) { command += localFile.substring(localFile.lastIndexOf("/") + 1); } else if (localFile.lastIndexOf(File.separator) > 0) { command += localFile.substring(localFile.lastIndexOf(File.separator) + 1); } else { command += localFile; } command += "\n"; out.write(command.getBytes()); out.flush(); if (checkAck(in) != 0) { throw new Exception("Error in checkAck()"); } fis = new FileInputStream(localFile); byte[] buf = new byte[1024]; while (true) { int len = fis.read(buf, 0, buf.length); if (len <= 0) break; out.write(buf, 0, len); } fis.close(); fis = null; buf[0] = 0; out.write(buf, 0, 1); out.flush(); if (checkAck(in) != 0) { throw new Exception("Error in checkAck()"); } out.close(); channel.disconnect(); session.disconnect(); } catch (Exception e) { throw e; } finally { try { if (fis != null) fis.close(); } catch (Exception ee) { } } } SSHClient(String hostname, String username, String password); void scpFileToRemote(String localFile, String remoteTargetDirectory); void scpFileToLocal(String rfile, String lfile); SSHClientOutput execCommand(String command); SSHClientOutput execCommand(String command, int timeoutSeconds, Logger logAppender);  }### Answer:
@Test public void testScp() throws Exception { if (isRemote == false) return; SSHClient ssh = new SSHClient(this.hostname, this.username, this.password); File tmpFile = FileUtil.createLocalTempFile(new File("/tmp/test_scp"), "temp_", false); ssh.scpFileToRemote(tmpFile.getAbsolutePath(), "/tmp"); }