1 package org
.argeo
.maintenance
.backup
;
3 import java
.io
.Console
;
4 import java
.io
.IOException
;
5 import java
.util
.HashSet
;
8 import org
.apache
.sshd
.client
.SshClient
;
9 import org
.apache
.sshd
.client
.channel
.ClientChannel
;
10 import org
.apache
.sshd
.client
.channel
.ClientChannelEvent
;
11 import org
.apache
.sshd
.client
.future
.ConnectFuture
;
12 import org
.apache
.sshd
.client
.session
.ClientSession
;
13 import org
.apache
.sshd
.common
.util
.io
.NoCloseInputStream
;
14 import org
.apache
.sshd
.common
.util
.io
.NoCloseOutputStream
;
16 public class SshSync
{
17 public static void main(String
[] args
) {
19 String login
= System
.getProperty("user.name");
20 Console console
= System
.console();
21 char[] password
= console
.readPassword();
22 String host
= "localhost";
25 try (SshClient client
= SshClient
.setUpDefaultClient()) {
28 // SimpleClient simpleClient= AbstractSimpleClientSessionCreator.wrap(client, null);
29 // simpleClient.sessionLogin(host, login, password);
31 ConnectFuture connectFuture
= client
.connect(login
, host
, port
);
32 connectFuture
.await();
33 ClientSession session
= connectFuture
.getSession();
37 session
.addPasswordIdentity(new String(password
));
38 session
.auth().verify(1000l);
40 try (ClientChannel channel
= session
.createChannel(ClientChannel
.CHANNEL_SHELL
)) {
41 channel
.setIn(new NoCloseInputStream(System
.in
));
42 channel
.setOut(new NoCloseOutputStream(System
.out
));
43 channel
.setErr(new NoCloseOutputStream(System
.err
));
46 Set
<ClientChannelEvent
> events
= new HashSet
<>();
47 events
.add(ClientChannelEvent
.CLOSED
);
48 channel
.waitFor(events
, 0);
55 } catch (IOException e
) {
56 // TODO Auto-generated catch block