public interface

Transport

implements SSHPacketHandler
net.schmizz.sshj.transport.Transport
Known Indirect Subclasses

Class Overview

Transport layer of the SSH protocol.

Summary

Public Methods
abstract void addHostKeyVerifier(HostKeyVerifier hkv)
Adds the specified verifier.
abstract void disconnect(DisconnectReason reason, String message)
Send a disconnect packet with the given reason and message, and closes this transport.
abstract void disconnect()
Send a disconnection packet with reason as BY_APPLICATION, and closes this transport.
abstract void disconnect(DisconnectReason reason)
Send a disconnect packet with the given reason, and closes this transport.
abstract void doKex()
Do key exchange and algorithm negotiation.
abstract String getClientVersion()
abstract Config getConfig()
abstract DisconnectListener getDisconnectListener()
abstract int getHeartbeatInterval()
abstract String getRemoteHost()
abstract int getRemotePort()
abstract String getServerVersion()
Returns the version string as sent by the SSH server for identification purposes, e.g.
abstract Service getService()
abstract byte[] getSessionID()
abstract int getTimeout()
abstract void init(String host, int port, InputStream in, OutputStream out)
Sets the host information and the streams to be used by this transport.
abstract boolean isAuthenticated()
abstract boolean isRunning()
abstract void join(int timeout, TimeUnit unit)
Joins the thread calling this method to the transport's death.
abstract void join()
Joins the thread calling this method to the transport's death.
abstract void reqService(Service service)
Request a SSH service represented by a Service instance.
abstract long sendUnimplemented()
Sends SSH_MSG_UNIMPLEMENTED in response to the last packet received.
abstract void setAuthenticated()
Informs this transport that authentication has been completed.
abstract void setDisconnectListener(DisconnectListener listener)
Specify a listener that will be notified upon disconnection.
abstract void setHeartbeatInterval(int interval)
abstract void setService(Service service)
Sets the currently active Service.
abstract void setTimeout(int timeout)
Set a timeout for methods that may block.
abstract long write(SSHPacket payload)
Write a packet over this transport.
[Expand]
Inherited Methods
From interface net.schmizz.sshj.common.SSHPacketHandler

Public Methods

public abstract void addHostKeyVerifier (HostKeyVerifier hkv)

Adds the specified verifier.

Parameters
hkv The host key verifier

public abstract void disconnect (DisconnectReason reason, String message)

Send a disconnect packet with the given reason and message, and closes this transport.

Parameters
reason The reason code for this disconnect
message The text message

public abstract void disconnect ()

Send a disconnection packet with reason as BY_APPLICATION, and closes this transport.

public abstract void disconnect (DisconnectReason reason)

Send a disconnect packet with the given reason, and closes this transport.

Parameters
reason Reason for disconnecting

public abstract void doKex ()

Do key exchange and algorithm negotiation. This can be the initial one or for algorithm renegotiation.

Throws
TransportException if there was an error during key exchange

public abstract String getClientVersion ()

Returns
  • the version string used by this client to identify itself to an SSH server, e.g. "SSHJ_3_0"

public abstract Config getConfig ()

Returns
  • the Config associated with this transport.

public abstract DisconnectListener getDisconnectListener ()

Returns
  • the current disconnect listener.

public abstract int getHeartbeatInterval ()

Returns
  • the interval in seconds at which a heartbeat message is sent to the server

public abstract String getRemoteHost ()

Returns
  • the hostname to which this transport is connected.

public abstract int getRemotePort ()

Returns
  • the port number on the remote host to which this transport is connected.

public abstract String getServerVersion ()

Returns the version string as sent by the SSH server for identification purposes, e.g. "OpenSSH_$version".

If the transport has not yet been initialized via init(String, int, InputStream, OutputStream), it will be null.

Returns
  • server's version string (may be null)

public abstract Service getService ()

Returns
  • the currently active Service instance.

public abstract byte[] getSessionID ()

Returns
  • the session identifier assigned by server

public abstract int getTimeout ()

Returns
  • the timeout that is currently set for blocking operations.

public abstract void init (String host, int port, InputStream in, OutputStream out)

Sets the host information and the streams to be used by this transport. Identification information is exchanged with the server. A TransportException is thrown in case of SSH protocol version incompatibility.

Parameters
host Server's hostname
port Server's port
in Input stream for the connection
out Output stream for the connection
Throws
TransportException if there is an error during exchange of identification information

public abstract boolean isAuthenticated ()

Returns
  • whether the transport thinks it is authenticated.

public abstract boolean isRunning ()

Returns

public abstract void join (int timeout, TimeUnit unit)

Joins the thread calling this method to the transport's death.

Parameters
timeout
unit
Throws
TransportException if the transport dies of an exception

public abstract void join ()

Joins the thread calling this method to the transport's death.

Throws
TransportException if the transport dies of an exception

public abstract void reqService (Service service)

Request a SSH service represented by a Service instance. A separate call to setService(Service) is not needed.

Parameters
service The SSH service to be requested
Throws
TransportException if the request failed for any reason

public abstract long sendUnimplemented ()

Sends SSH_MSG_UNIMPLEMENTED in response to the last packet received.

Returns
  • the sequence number of the packet sent
Throws
TransportException if an error occured sending the packet

public abstract void setAuthenticated ()

Informs this transport that authentication has been completed. This method must be called after successful authentication, so that delayed compression may become effective if applicable.

public abstract void setDisconnectListener (DisconnectListener listener)

Specify a listener that will be notified upon disconnection.

Parameters
listener

public abstract void setHeartbeatInterval (int interval)

Parameters
interval The interval in seconds, 0 means no hearbeat

public abstract void setService (Service service)

Sets the currently active Service. Handling of non-transport-layer packets is delegated to that service.

For this method to be successful, at least one service request via reqService(Service) must have been successful (not necessarily for the service being set).

Parameters
service (null-ok) the Service

public abstract void setTimeout (int timeout)

Set a timeout for methods that may block.

Parameters
timeout The timeout in seconds

public abstract long write (SSHPacket payload)

Write a packet over this transport.

The payload SSHPacket should have 5 bytes free at the beginning to avoid a performance penalty associated with making space for header bytes (packet length, padding length).

Parameters
payload The SSHPacket containing data to send
Returns
  • sequence number of the sent packet
Throws
TransportException if an error occurred sending the packet