private void send( Session session, Blob blob, String remotePath, int localIndex, OutputStream output) throws IOException, JSchException { long size = blob.getSize(); String exec = String.format("scp -t \"%s\"", toLiteral(remotePath)); //$NON-NLS-1$ String header = String.format("C0644 %d BLOB-%d", size, localIndex); //$NON-NLS-1$ YSLOG.info("I01001", size, remotePath); long start = System.currentTimeMillis(); ChannelExec channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(exec); channel.setErrStream(output, true); try (InputStream stdin = channel.getInputStream(); OutputStream stdout = channel.getOutputStream()) { channel.connect(); stdout.write(header.getBytes(ENCODING)); stdout.write('\n'); stdout.flush(); checkAck(blob, stdin); putBlob(blob, stdout); stdout.write(0); stdout.flush(); checkAck(blob, stdin); } finally { channel.disconnect(); } long end = System.currentTimeMillis(); YSLOG.info("I01002", size, remotePath, end - start); }