public final class Ssh extends Object
This class implements Shell
interface. In order to use
it, just make an instance and call
exec(String, java.io.InputStream,
java.io.OutputStream, java.io.OutputStream)
exec()}:
String hello = new Shell.Plain( new SSH( "ssh.example.com", 22, "yegor", "-----BEGIN RSA PRIVATE KEY-----..." ) ).exec("echo 'Hello, world!'");
It is highly recommended to use classes from Shell
interface,
they will simplify operations.
Shell.Empty, Shell.Fake, Shell.Plain, Shell.Safe, Shell.Verbose
Modifier and Type | Field and Description |
---|---|
static int |
PORT
Default SSH port.
|
Constructor and Description |
---|
Ssh(InetAddress adr,
int prt,
String user,
URL priv)
Constructor.
|
Ssh(InetAddress adr,
String user,
String priv)
Constructor.
|
Ssh(InetAddress adr,
String user,
URL priv)
Constructor.
|
Ssh(String adr,
int prt,
String user,
String priv)
Constructor.
|
Ssh(String adr,
int prt,
String user,
String priv,
String passphrs)
Constructor.
|
Ssh(String adr,
int prt,
String user,
URL priv)
Constructor.
|
Ssh(String adr,
String user,
String priv)
Constructor.
|
Ssh(String adr,
String user,
URL priv)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static String |
escape(String arg)
Escape SSH argument.
|
int |
exec(String command,
InputStream stdin,
OutputStream stdout,
OutputStream stderr)
Execute and return exit code.
|
protected com.jcraft.jsch.Session |
session()
Create and return a session, connected.
|
public static final int PORT
public Ssh(String adr, String user, URL priv) throws IOException
adr
- IP addressuser
- Loginpriv
- Private SSH keyIOException
- If failspublic Ssh(InetAddress adr, String user, URL priv) throws IOException
adr
- IP addressuser
- Loginpriv
- Private SSH keyIOException
- If failspublic Ssh(String adr, String user, String priv) throws UnknownHostException
adr
- IP addressuser
- Loginpriv
- Private SSH keyUnknownHostException
- If failspublic Ssh(InetAddress adr, String user, String priv) throws UnknownHostException
adr
- IP addressuser
- Loginpriv
- Private SSH keyUnknownHostException
- If failspublic Ssh(String adr, int prt, String user, URL priv) throws IOException
adr
- IP addressprt
- Port of serveruser
- Loginpriv
- Private SSH keyIOException
- If failspublic Ssh(InetAddress adr, int prt, String user, URL priv) throws IOException
adr
- IP addressprt
- Port of serveruser
- Loginpriv
- Private SSH keyIOException
- If failspublic Ssh(String adr, int prt, String user, String priv) throws UnknownHostException
adr
- IP addressprt
- Port of serveruser
- Loginpriv
- Private SSH keyUnknownHostException
- If failspublic Ssh(String adr, int prt, String user, String priv, String passphrs) throws UnknownHostException
adr
- IP addressprt
- Port of serveruser
- Loginpriv
- Private SSH keypassphrs
- Pass phrase for encrypted priv. keyUnknownHostException
- when host is unknown.public static String escape(String arg)
arg
- Argument to escape@RetryOnFailure(attempts=7, delay=1L, unit=MINUTES, verbose=false, randomize=true, types=java.io.IOException.class) protected com.jcraft.jsch.Session session() throws IOException
IOException
- If some IO problem insidepublic int exec(String command, InputStream stdin, OutputStream stdout, OutputStream stderr) throws IOException
Shell
exec
in interface Shell
command
- Commandstdin
- Stdin (will be closed)stdout
- Stdout (will be closed)stderr
- Stderr (will be closed)IOException
- If failsCopyright © 2012–2018 jcabi.com. All rights reserved.