Assert.notNull(uri, "uri should not be null");
Assert.notNull(file, "file must not be null");
boolean isFileCopied = false;
long timeout = System.currentTimeMillis() + waitTime;
while (!isFileCopied && System.currentTimeMillis() < timeout) {
final SshjSshClient client = getSSHClient(host, privateKey);
Assert.isTrue(file.exists(), "File to be copied to remote machine does not exist");
ByteSource byteSource = com.google.common.io.Files.asByteSource(file);
ByteSourcePayload payload = new ByteSourcePayload(byteSource);
long byteSourceSize = -1;
try {
byteSourceSize = byteSource.size();
payload.getContentMetadata().setContentLength(byteSourceSize);
}
catch (IOException ioe) {
throw new IllegalStateException("Unable to retrieve size for file to be copied to remote machine.", ioe);
}
client.put(uri.getPath(), payload);
if (client.exec("ls -al " + uri.getPath()).getExitStatus() == 0) {
ExecResponse statResponse = client.exec("stat --format=%s " + uri.getPath());
long copySize = Long.valueOf(statResponse.getOutput().trim());
if (copySize == byteSourceSize) {
isFileCopied = true;
}
}