import net.schmizz.sshj.xfer.InMemorySourceFile; import net.schmizz.sshj.xfer.scp.SCPFileTransfer; // allow any host ID and search for pw in JavaX-Secret static void scpUploadWithMkdirs(S user, S host, fS remotePath, final long length, final InputStream in) ctex { final SSHClient client = sshLogin(user, host); print("Logged in to SSH server " + user + "@" + host); try { S remoteDir = dropAfterLastSlash(remotePath); if (nempty(remoteDir)) client.newSFTPClient().mkdirs(remoteDir); print("Uploading to on " + user + "@" + host + ": " + remotePath); SCPFileTransfer fileTransfer = client.newSCPFileTransfer(); fileTransfer.upload(new InMemorySourceFile { public S getName() { ret "dummy"; } public long getLength() { ret length; } public InputStream getInputStream() { ret in; } }, remotePath); } finally { sshDisconnect(client); } }