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

22
LINES

< > BotCompany Repo | #1009981 // scpUpload

JavaX fragment (include) [tags: use-pretranspiled]

Uses 9724K of libraries. Click here for Pure Java version (3439L/20K).

1  
import net.schmizz.sshj.xfer.InMemorySourceFile;
2  
import net.schmizz.sshj.xfer.scp.SCPFileTransfer;
3  
4  
// allow any host ID and search for pw in JavaX-Secret
5  
// doesn't do mkdirs
6  
svoid scpUpload(S user, S host, S remotePath, long length, InputStream in) ctex {
7  
  final SSHClient client = sshLogin(user, host);
8  
  try {
9  
    SCPFileTransfer fileTransfer = client.newSCPFileTransfer();
10  
    fileTransfer.upload(new InMemorySourceFile {
11  
      public S getName() { ret "dummy"; }
12  
      public long getLength() { ret length; }
13  
      public InputStream getInputStream() { ret in; }
14  
    }, remotePath);
15  
  } finally {
16  
    sshDisconnect(client);
17  
  }
18  
}
19  
20  
svoid scpUpload(S user, S host, S remotePath, byte[] data) {
21  
  scpUpload(user, host, remotePath, l(data), byteArrayInputStream(data));
22  
}

Author comment

Began life as a copy of #1004835

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: #1009981
Snippet name: scpUpload
Eternal ID of this version: #1009981/8
Text MD5: 7dd15c816e4f3eadb540bb41efaccaaf
Transpilation MD5: 6cdd2c6ecc8a6a7e42d94aca377b0f49
Author: stefan
Category: javax / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-07-14 17:20:49
Source code size: 795 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 339 / 417
Version history: 7 change(s)
Referenced in: [show references]