// Cmmmm <length> <filename>
// a single file copy, mmmmm is mode. Example: C0644 299 group
String[] tokens = nextLine.data.split(" ");
if (tokens.length != 3) {
throw new SshException("Invalid SCP line: " + nextLine);
}
fileInfo = new FileInfo(tokens[0].substring(1), Long.parseLong(tokens[1]), tokens[2]);
break;
}
throw new SshException("Unexpected SCP status: " + nextLine);
}
toStdin.write(0x0);
toStdin.flush();
try {
long remain = fileInfo.length;
while (remain > 0) {
int readSize = (int) Math.min(buffer.length, remain);
int actuallyRead = fromStdout.read(buffer, 0, readSize);
if (actuallyRead < 0) {
throw new EOFException();
}
destOutputStream.write(buffer, 0, actuallyRead);
remain -= actuallyRead;
}
} finally {
IoUtils.safeClose(destOutputStream);
}
parseFinalLine(readResponseLine());
toStdin.write(0x0);
toStdin.flush();
// Wait for everything to finish
int flags = channel.waitFor(ClientChannel.EOF, timeout.getTotalMilliseconds());
if ((flags & ClientChannel.TIMEOUT) != 0) {
throw new SshException("Timeout while waiting for SSH task to complete");
}
}