2008 2008 Ericsson AB, All Rights Reserved The contents of this file are subject to the Erlang Public License, Version 1.1, (the "License"); you may not use this file except in compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Initial Developer of the Original Code is Ericsson AB. ssh_connection Ingela Anderton Andin
ssh_connection This module provides an API to the ssh connection protocol.

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 and/or abstractions to indicate the intended use of the data type:

boolean() = true | false

string() = list of ASCII characters

timeout() = infinity | integer() - in milliseconds.

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

ssh_channel_id() = integer()

ssh_data_type_code() = 1 ("stderr") | 0 ("normal") are currently valid values see RFC 4254 section 5.2.

ssh_request_status() = success | failure

MESSAGES SENT TO CHANNEL PROCESSES

As a result of the ssh connection protocol messages on the form will be sent to a channel process. The term will contain information regarding the ssh connection protocol event, for details see the ssh channel behavior callback handle_ssh_msg/2

adjust_window(ConnectionRef, ChannelId, NumOfBytes) -> ok Adjusts the ssh flowcontrol window. ConnectionRef = ssh_connection_ref() ChannelId = ssh_channel_id() NumOfBytes = integer()

Adjusts the ssh flowcontrol window.

This will be taken care of by the ssh_channel behavior when the callback handle_ssh_msg/2 has returned after processing a {ssh_cm, ssh_connection_ref(), {data, ssh_channel_id(), ssh_data_type_code(), binary()}} message, and should normally not be called explicitly.

close(ConnectionRef, ChannelId) -> ok Sends a close message on the channel ChannelId. ConnectionRef = ssh_connection_ref() ChannelId = ssh_channel_id()

Sends a close message on the channel ChannelId

This function will be called by the ssh channel behavior when the channel is terminated see ssh_channel(3) and should normally not be called explicitly.

exec(ConnectionRef, ChannelId, Command, TimeOut) -> ssh_request_status() Will request that the server start the execution of the given command. ConnectionRef = ssh_connection_ref() ChannelId = ssh_channel_id() Command = string() Timeout = timeout()

Will request that the server start the execution of the given command, the result will be received as:

N X {ssh_cm, ssh_connection_ref(), {data, ssh_channel_id(), ssh_data_type_code(), binary() = Data}} The result of executing the command may be only one line or thousands of lines depending on the command. 1 X {ssh_cm, ssh_connection_ref(), {eof, ssh_channel_id()}} Indicates that no more data will be sent. 0 or 1 X {ssh_cm, ssh_connection_ref(), {exit_signal, ssh_channel_id(), string() = ExitSignal, string() = ErrorMsg, string() = LanguageString}} Not all systems send signals. For details on valid string values see RFC 4254 section 6.10 0 or 1 X {ssh_cm, ssh_connection_ref(), {exit_status, ssh_channel_id(), integer() = ExitStatus}} It is recommended by the ssh connection protocol that this message shall be sent, but that may not always be the case. 1 X {ssh_cm, ssh_connection_ref(), {closed, ssh_channel_id()}} Indicates that the ssh channel started for the execution of the command has now been shutdown.

These message should be handled by the client. The ssh channel behavior can be used when writing a client.

exit_status(ConnectionRef, ChannelId, Status) -> ok Sends the exit status of a command to the client. ConnectionRef = ssh_connection_ref() ChannelId = ssh_channel_id() Status = integer()

Sends the exit status of a command to the client.

reply_request(ConnectionRef, WantReply, Status, CannelId) -> ok Send status replies to requests that want such replies. ConnectionRef = ssh_connection_ref() WantReply = boolean() Status = ssh_request_status() ChannelId = ssh_channel_id()

Sends status replies to requests where the requester has stated that they want a status report e.i . WantReply = true, if WantReply is false calling this function will be a "noop". Should be called after handling an ssh connection protocol message containing a WantReply boolean value. See the ssh_channel behavior callback handle_ssh_msg/2

send(ConnectionRef, ChannelId, Data) -> send(ConnectionRef, ChannelId, Data, Timeout) -> send(ConnectionRef, ChannelId, Type, Data) -> send(ConnectionRef, ChannelId, Type, Data, TimeOut) -> ok | {error, timeout} Sends channel data ConnectionRef = ssh_connection_ref() ChannelId = ssh_channel_id() Data = binary() Type = ssh_data_type_code() Timeout = timeout()

Sends channel data.

send_eof(ConnectionRef, ChannelId) -> ok Sends eof on the channel ChannelId. ConnectionRef = ssh_connection_ref() ChannelId = ssh_channel_id()

Sends eof on the channel ChannelId.

session_channel(ConnectionRef, Timeout) -> session_channel(ConnectionRef, InitialWindowSize, MaxPacketSize, Timeout) -> {ok, ssh_channel_id()} | {error, Reason} 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. ConnectionRef = ssh_connection_ref() InitialWindowSize = integer() MaxPacketSize = integer() Timeout = timeout() Reason = term()

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) -> ssh_request_status() Environment variables may be passed to the shell/command to be started later. ConnectionRef = ssh_connection_ref() ChannelId = ssh_channel_id() Var = string() Value = string() Timeout = timeout()

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

shell(ConnectionRef, ChannelId) -> ssh_request_status() Will request that the user's default shell (typically defined in /etc/passwd in UNIX systems) be started at the other end. ConnectionRef = ssh_connection_ref() ChannelId = ssh_channel_id()

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

subsystem(ConnectionRef, ChannelId, Subsystem, Timeout) -> ssh_request_status() ConnectionRef = ssh_connection_ref() ChannelId = ssh_channel_id() Subsystem = string() Timeout = timeout()

Sends a request to execute a predefined subsystem.