!636 import net.schmizz.sshj.SSHClient; import net.schmizz.sshj.xfer.InMemorySourceFile; import net.schmizz.sshj.xfer.scp.SCPFileTransfer; main { psvm { String hostKey = ""; String remoteDir = "/root/www-8080/speech/"; String remoteFilePath = remoteDir + "bla.php"; String host = "tinybrain.de", user = "root"; System.out.println("Uploading to: " + remoteFilePath); //System.out.print("Password for " + user + "@" + host + ": "); char[] pw = loadTextFile("input/password.txt", null).toCharArray(); final SSHClient client = new SSHClient(); client.loadKnownHosts(); if (!isEmpty(hostKey)) client.addHostKeyVerifier(hostKey); client.connect(host); try { client.authPassword(user, pw); client.newSFTPClient().mkdirs(remoteDir); uploadBySCP(client, remoteFilePath, text); System.out.println("File copied!"); } finally { client.disconnect(); } } private static void uploadBySCP(SSHClient client, String remoteFilePath, String text) throws IOException { uploadBySCP(client, remoteFilePath, text.getBytes("UTF-8")); } private static void uploadBySCP(SSHClient client, String remoteFilePath, final byte[] data) throws IOException { SCPFileTransfer fileTransfer = client.newSCPFileTransfer(); fileTransfer.upload(new InMemorySourceFile() { public String getName() { return "index.php"; } public long getLength() { return data.length; } public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(data); } }, remoteFilePath); } static boolean isEmpty(String s) { return s == null || s.length() == 0; } }
Began life as a copy of #2000401
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: | #654 |
Snippet name: | Upload to tinybrain.de by SCP (developing) |
Eternal ID of this version: | #654/1 |
Text MD5: | 54e46202d481b4684d91117459c76a15 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-06-29 20:10:07 |
Source code size: | 1779 bytes / 57 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 806 / 602 |
Referenced in: | [show references] |