X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.core%2Fsrc%2Forg%2Fargeo%2Fssh%2FSsh.java;h=68dd912ec1ff0753d38abf963294e6651c1ac01a;hb=c718f8be43b6ee3b1ba111c2a22c9037e35b872f;hp=0443098770ab8f44155fb7dec1d7c1157092d3af;hpb=9ab1f7dea15511711b13dfef91b6aba74cbfc651;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.core/src/org/argeo/ssh/Ssh.java b/org.argeo.core/src/org/argeo/ssh/Ssh.java index 044309877..68dd912ec 100644 --- a/org.argeo.core/src/org/argeo/ssh/Ssh.java +++ b/org.argeo.core/src/org/argeo/ssh/Ssh.java @@ -1,11 +1,8 @@ package org.argeo.ssh; -import java.io.IOException; import java.net.URI; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; @@ -13,39 +10,20 @@ import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; -import org.apache.sshd.client.channel.ClientChannel; -import org.apache.sshd.client.channel.ClientChannelEvent; -import org.apache.sshd.client.session.ClientSession; -import org.apache.sshd.common.util.io.NoCloseInputStream; -import org.apache.sshd.common.util.io.NoCloseOutputStream; -@SuppressWarnings("restriction") +/** Create an SSH shell. */ public class Ssh extends AbstractSsh { private final URI uri; + public Ssh(String username, String host, int port) { + this(AbstractSsh.toUri(username, host, port)); + } + public Ssh(URI uri) { this.uri = uri; openSession(uri); } - static void openShell(ClientSession session) { - try (ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)) { - channel.setIn(new NoCloseInputStream(System.in)); - channel.setOut(new NoCloseOutputStream(System.out)); - channel.setErr(new NoCloseOutputStream(System.err)); - channel.open(); - - Set events = new HashSet<>(); - events.add(ClientChannelEvent.CLOSED); - channel.waitFor(events, 0); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } finally { - session.close(false); - } - } - public static void main(String[] args) { Options options = getOptions(); CommandLineParser parser = new DefaultParser(); @@ -70,7 +48,7 @@ public class Ssh extends AbstractSsh { ssh.authenticate(); if (command.size() == 0) {// shell - openShell(ssh.getSession()); + AbstractSsh.openShell(ssh.getSession()); } else {// execute command }