Skip to content

Instantly share code, notes, and snippets.

@conorgriffin
Created February 22, 2021 14:58
Show Gist options
  • Save conorgriffin/db1b2c92c846722e5fc72407aeca6fed to your computer and use it in GitHub Desktop.
Save conorgriffin/db1b2c92c846722e5fc72407aeca6fed to your computer and use it in GitHub Desktop.
SSHJ's SFTPFileTransfer
private LocalDestFile downloadFile(final StreamCopier.Listener listener,
final RemoteResourceInfo remote,
final LocalDestFile local)
throws IOException {
final LocalDestFile adjusted = local.getTargetFile(remote.getName());
final RemoteFile rf = engine.open(remote.getPath());
try {
final RemoteFile.ReadAheadRemoteFileInputStream rfis = rf.new ReadAheadRemoteFileInputStream(16);
final OutputStream os = adjusted.getOutputStream();
try {
new StreamCopier(rfis, os, engine.getLoggerFactory())
.bufSize(engine.getSubsystem().getLocalMaxPacketSize())
.keepFlushing(false)
.listener(listener)
.copy();
} finally {
rfis.close();
os.close();
}
} finally {
rf.close();
}
return adjusted;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment