Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

22
LINES

< > BotCompany Repo | #1009983 // scpUploadWithMkdirs

JavaX fragment (include)

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);
  }
}

Author comment

Began life as a copy of #1009981

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009983
Snippet name: scpUploadWithMkdirs
Eternal ID of this version: #1009983/6
Text MD5: 2c74cf7c92bc2962f594a08627e97d6f
Author: stefan
Category: javax / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-24 03:08:23
Source code size: 920 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 368 / 412
Version history: 5 change(s)
Referenced in: [show references]