1 | !636 |
2 | |
3 | import net.schmizz.sshj.SSHClient; |
4 | import net.schmizz.sshj.xfer.InMemorySourceFile; |
5 | import net.schmizz.sshj.xfer.scp.SCPFileTransfer; |
6 | |
7 | main {
|
8 | psvm {
|
9 | String hostKey = ""; |
10 | String remoteDir = "/root/www-8080/speech/"; |
11 | String remoteFilePath = remoteDir + "bla.php"; |
12 | String host = "tinybrain.de", user = "root"; |
13 | |
14 | System.out.println("Uploading to: " + remoteFilePath);
|
15 | //System.out.print("Password for " + user + "@" + host + ": ");
|
16 | char[] pw = loadTextFile("input/password.txt", null).toCharArray();
|
17 | |
18 | final SSHClient client = new SSHClient(); |
19 | client.loadKnownHosts(); |
20 | if (!isEmpty(hostKey)) |
21 | client.addHostKeyVerifier(hostKey); |
22 | client.connect(host); |
23 | try {
|
24 | client.authPassword(user, pw); |
25 | client.newSFTPClient().mkdirs(remoteDir); |
26 | uploadBySCP(client, remoteFilePath, text); |
27 | System.out.println("File copied!");
|
28 | } finally {
|
29 | client.disconnect(); |
30 | } |
31 | } |
32 | |
33 | private static void uploadBySCP(SSHClient client, String remoteFilePath, String text) throws IOException {
|
34 | uploadBySCP(client, remoteFilePath, text.getBytes("UTF-8"));
|
35 | } |
36 | |
37 | private static void uploadBySCP(SSHClient client, String remoteFilePath, final byte[] data) throws IOException {
|
38 | SCPFileTransfer fileTransfer = client.newSCPFileTransfer(); |
39 | fileTransfer.upload(new InMemorySourceFile() {
|
40 | public String getName() {
|
41 | return "index.php"; |
42 | } |
43 | |
44 | public long getLength() {
|
45 | return data.length; |
46 | } |
47 | |
48 | public InputStream getInputStream() throws IOException {
|
49 | return new ByteArrayInputStream(data); |
50 | } |
51 | }, remoteFilePath); |
52 | } |
53 | |
54 | static boolean isEmpty(String s) {
|
55 | return s == null || s.length() == 0; |
56 | } |
57 | } |
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: | 1061 / 851 |
| Referenced in: | [show references] |