import net.schmizz.sshj.xfer.InMemorySourceFile; import net.schmizz.sshj.xfer.scp.SCPFileTransfer; // allow any host ID and search for pw in JavaX-Secret // doesn't do mkdirs static void scpUpload(S user, S host, fS remotePath, final long length, final InputStream in) ctex { final SSHClient client = sshLogin(user, host); try { SCPFileTransfer fileTransfer = client.newSCPFileTransfer(); fileTransfer.upload(new InMemorySourceFile { public S getName() { ret remotePath; } public long getLength() { ret length; } public InputStream getInputStream() { ret in; } }, remotePath); } finally { client.disconnect(); } }