ssh_connection(3)

MODULE
SSH - This module provides an API to the ssh connection protocol.

DESCRIPTION

This module provides an API to the ssh connection protocol. Not all features of the connection protocol are officially supported yet. Only the ones supported are documented here.

COMMON DATA TYPES

Type definitions that are used more than once in this module:

boolean() = true | false

string() = list of ASCII characters

ssh_connection_ref() - opaque to the user returned by ssh:connect/[1, 2, 3] or sent to a ssh channel processes

ssh_system_ref() - opaque to the user returned by ssh:daemon/[1, 2, 3]

MESSAGES SENT TO CHANNEL PROCESSES

As a result of the connection protocol the following messages may be sent to a channel process.

    {ssh_cm, ConnectionRef, {open, ChannelId, RemoteChannelId, {session}}}:

    {ssh_cm, ConnectionRef, {subsystem, ChannelId, WantReply, Name}}:

    {ssh_cm, ConnectionRef, {closed, ChannelId}}:

    {ssh_cm, ConnectionRef, {data, ChannelId, Type, Data}}:

    {ssh_cm, ConnectionRef, {eof, ChannelId}}:

    {ssh_cm, ConnectionRef, {exit_signal, ChannelId, Signal, Err, Lang}} :

    {ssh_cm, ConnectionRef, {exit_status, ChannelId, _Status}}:

    {ssh_cm, ConnectionRef, {shell, WantReply}}:

    {ssh_cm, ConnectionRef, {pty, ChannelId, WantReply, Pty}}:

    {ssh_cm, ConnectionRef, {window_change, ChannelId, Width, Height, PixWidth, PixHeight}}:

EXPORTS

adjust_window(ConnectionRef, Channel, Bytes) -> ok

    Types
         ConnectionRef = ssh_connection_ref()
         ChannelId = integer()
         Bytes = integer()

    Adjusts the ssh flowcontrol window. Should be called after handling a {ssh_cm, ConnectionRef, {data, ChannelId, Type, Data}} message in the following way: ssh_connection:adjust_window(ConnectionRef, ChannelId, size(Data)),

 close(ConnectionRef, ChannelId) -> ok

    Types
         ConnectionRef = ssh_connection_ref()
         ChannelId = integer()

    Sends a close message on the channel ChannelId

exec(ConnectionRef, ChannelId, Command, TimeOut) -> success | failiure

    Types
         ConnectionRef = ssh_connection_ref()
         ChannelId = integer()
         Command = string()
        Timeout = infinity | integer()

    Will request that the server start the execution of the given command. Result will be received as N x {ssh_cm, ConnectionRef, {data, ChannelId, Type, Data}} messages followed by {ssh_cm, ConnectionRef, {eof, ChannelId}} {ssh_cm, ConnectionRef, {exit_status, ChannelId, Status}}, {ssh_cm, ConnectionRef, {closed, ChannelId}}

reply_request(ConnectionRef, WantReply, Status, CannelId) -> ok

    Types
         ConnectionRef = ssh_connection_ref()
         WantReply = boolean()
         Status = success | failure
         ChannelId = integer()

    Send status replies to requests that want such replies. Should be called after handling an ssh_cm-message containing a WantReply.

send(ConnectionRef, ChannelId, Data) ->
send(ConnectionRef, ChannelId, Data, Timeout) ->
send(ConnectionRef, ChannelId, Type, Data) ->
send(ConnectionRef, ChannelId, Type, Data, TimeOut) -> ok | {error, timeout}

    Types
         ConnectionRef = ssh_connection_ref()
         ChannelId = integer()
         Data = binary()
         Type = 0 | 1 see RFC 4254
         Timeout = infinity | integer()

    Sends channel data.

send_eof(ConnectionRef, ChannelId) -> ok

    Types
         ConnectionRef = ssh_connection_ref()
         ChannelId = integer()

    Sends eof on the channel ChannelId.

session_channel(ConnectionRef, Timeout) ->
session_channel(ConnectionRef, InitialWindowSize, MaxPacketSize, Timeout) -> {ok, ChannleId} | {error, Reason}

    Types
         ConnectionRef = ssh_connection_ref()
         InitialWindowSize = integer()
         MaxPacketSize = integer()
         Timeout = infinity | integer()

    Opens a channel for a ssh session. A session is a remote execution of a program. The program may be a shell, an application, a system command, or some built-in subsystem.

setenv(ConnectionRef, ChannelId, Var, Value, TimeOut) -> success | failure

    Types
         ConnectionRef = ssh_connection_ref()
         ChannelId = integer()
         Var = string()
         Value = string()
         Timeout = infinity | integer()

    Environment variables may be passed to the shell/command to be started later.

shell(ConnectionRef, ChannelId) -> success | failure

    Types
         ConnectionRef = ssh_connection_ref()
         ChannelId = integer()

    Will request that the user's default shell (typically defined in /etc/passwd in UNIX systems) be started at the other end. Messages for the caller to handle:

subsystem(ConnectionRef, ChannelId, Subsystem, Timeout) -> success | failure

    Types
         ConnectionRef = ssh_connection_ref()
         ChannelId = integer()
         Subsystem = string()
         Timeout = infinity | integer()

    Sends a request to execute a predefined subsystem