private void parseAndFetchFile(final String serverResponse, final File localFile, final OutputStream out, final InputStream in) throws IOException, JSchException { int start = 0; int end = serverResponse.indexOf(' ', start + 1); start = end + 1; end = serverResponse.indexOf(' ', start + 1); final long filesize = Long.parseLong(serverResponse.substring(start, end)); final String filename = serverResponse.substring(end + 1); log("Receiving: " + filename + " : " + filesize); final File transferFile = localFile.isDirectory() ? new File(localFile, filename) : localFile; fetchFile(transferFile, filesize, out, in); waitForAck(in); sendAck(out); }
throws IOException, JSchException { final byte[] buf = new byte[BUFFER_SIZE]; sendAck(out);
/** * Carry out the transfer. * @throws IOException on i/o errors * @throws JSchException on errors detected by scp */ @Override public void execute() throws IOException, JSchException { String command = "scp -f "; if (isRecursive) { command += "-r "; } if (getCompressed()) { command += "-C "; } command += remoteFile; final Channel channel = openExecChannel(command); try { // get I/O streams for remote scp final OutputStream out = channel.getOutputStream(); final InputStream in = channel.getInputStream(); channel.connect(); sendAck(out); startRemoteCpProtocol(in, out, localFile); } finally { if (channel != null) { channel.disconnect(); } } log("done\n"); }