User's Guide
Reference Manual
Release Notes
PDF
Top

Common Test
Reference Manual
Version 1.6.2

Expand All
Contract All

Table of Contents

- common_test
  - Top of manual page
  - Module:all/0
  - Module:groups/0
  - Module:suite/0
  - Module:init_per_suite/1
  - Module:end_per_suite/1
  - Module:group/1
  - Module:init_per_group/2
  - Module:end_per_group/2
  - Module:init_per_testcase/2
  - Module:end_per_testcase/2
  - Module:Testcase/0
  - Module:Testcase/1
- ct_run
- ct
  - Top of manual page
  - abort_current_testcase/1
  - add_config/2
  - break/1
  - break/2
  - capture_get/0
  - capture_get/1
  - capture_start/0
  - capture_stop/0
  - comment/1
  - comment/2
  - continue/0
  - continue/1
  - decrypt_config_file/2
  - decrypt_config_file/3
  - encrypt_config_file/2
  - encrypt_config_file/3
  - fail/1
  - fail/2
  - get_config/1
  - get_config/2
  - get_config/3
  - get_status/0
  - get_target_name/1
  - get_timetrap_info/0
  - install/1
  - listenv/1
  - log/1
  - log/2
  - log/3
  - log/4
  - make_priv_dir/0
  - notify/2
  - pal/1
  - pal/2
  - pal/3
  - pal/4
  - parse_table/1
  - print/1
  - print/2
  - print/3
  - print/4
  - reload_config/1
  - remove_config/2
  - require/1
  - require/2
  - run/1
  - run/2
  - run/3
  - run_test/1
  - run_testspec/1
  - sleep/1
  - start_interactive/0
  - step/3
  - step/4
  - stop_interactive/0
  - sync_notify/2
  - testcases/2
  - timetrap/1
  - userdata/2
  - userdata/3
- ct_master
  - Top of manual page
  - abort/0
  - abort/1
  - basic_html/1
  - progress/0
  - run/1
  - run/3
  - run/4
  - run_on_node/2
  - run_on_node/3
  - run_test/2
- ct_cover
  - Top of manual page
  - add_nodes/1
  - remove_nodes/1
- ct_ftp
  - Top of manual page
  - cd/2
  - close/1
  - delete/2
  - get/3
  - ls/2
  - open/1
  - put/3
  - recv/2
  - recv/3
  - send/2
  - send/3
  - type/2
- ct_ssh
  - Top of manual page
  - apread/4
  - apread/5
  - apwrite/4
  - apwrite/5
  - aread/3
  - aread/4
  - awrite/3
  - awrite/4
  - close/2
  - close/3
  - connect/1
  - connect/2
  - connect/3
  - del_dir/2
  - del_dir/3
  - delete/2
  - delete/3
  - disconnect/1
  - exec/2
  - exec/3
  - exec/4
  - get_file_info/2
  - get_file_info/3
  - list_dir/2
  - list_dir/3
  - make_dir/2
  - make_dir/3
  - make_symlink/3
  - make_symlink/4
  - open/3
  - open/4
  - opendir/2
  - opendir/3
  - position/3
  - position/4
  - pread/4
  - pread/5
  - pwrite/4
  - pwrite/5
  - read/3
  - read/4
  - read_file/2
  - read_file/3
  - read_file_info/2
  - read_file_info/3
  - read_link/2
  - read_link/3
  - read_link_info/2
  - read_link_info/3
  - receive_response/2
  - receive_response/3
  - receive_response/4
  - rename/3
  - rename/4
  - send/3
  - send/4
  - send/5
  - send_and_receive/3
  - send_and_receive/4
  - send_and_receive/5
  - send_and_receive/6
  - session_close/2
  - session_open/1
  - session_open/2
  - sftp_connect/1
  - subsystem/3
  - subsystem/4
  - write/3
  - write/4
  - write_file/3
  - write_file/4
  - write_file_info/3
  - write_file_info/4
- ct_netconfc
  - Top of manual page
  - action/2
  - action/3
  - close_session/1
  - close_session/2
  - copy_config/3
  - copy_config/4
  - create_subscription/1
  - create_subscription/2
  - create_subscription/3
  - create_subscription/4
  - create_subscription/5
  - create_subscription/6
  - delete_config/2
  - delete_config/3
  - edit_config/3
  - edit_config/4
  - format_data/2
  - get/2
  - get/3
  - get_capabilities/1
  - get_capabilities/2
  - get_config/3
  - get_config/4
  - get_event_streams/2
  - get_event_streams/3
  - get_session_id/1
  - get_session_id/2
  - handle_msg/2
  - hello/1
  - hello/2
  - kill_session/2
  - kill_session/3
  - lock/2
  - lock/3
  - only_open/1
  - only_open/2
  - open/1
  - open/2
  - unlock/2
  - unlock/3
- ct_rpc
  - Top of manual page
  - app_node/2
  - app_node/3
  - app_node/4
  - call/4
  - call/5
  - call/6
  - cast/4
  - cast/5
- ct_snmp
  - Top of manual page
  - get_next_values/3
  - get_values/3
  - load_mibs/1
  - register_agents/2
  - register_users/2
  - register_usm_users/2
  - set_info/1
  - set_values/4
  - start/2
  - start/3
  - stop/1
  - unregister_agents/1
  - unregister_users/1
  - update_usm_users/2
- ct_telnet
  - Top of manual page
  - close/1
  - cmd/2
  - cmd/3
  - cmdf/3
  - cmdf/4
  - cont_log/2
  - end_log/0
  - expect/2
  - expect/3
  - get_data/1
  - open/1
  - open/2
  - open/3
  - open/4
  - send/2
  - sendf/3
- unix_telnet
- ct_slave
  - Top of manual page
  - start/1
  - start/2
  - start/3
  - stop/1
  - stop/2
- ct_hooks
  - Top of manual page
  - Module:init/2
  - Module:pre_init_per_suite/3
  - Module:post_init_per_suite/4
  - Module:pre_init_per_group/3
  - Module:post_init_per_group/4
  - Module:pre_init_per_testcase/3
  - Module:post_end_per_testcase/4
  - Module:pre_end_per_group/3
  - Module:post_end_per_group/4
  - Module:pre_end_per_suite/3
  - Module:post_end_per_suite/4
  - Module:on_tc_fail/3
  - Module:on_tc_skip/3
  - Module:terminate/1
  - Module:id/1

# ct_ssh

### MODULE

ct_ssh

### MODULE SUMMARY

SSH/SFTP client module.

### DESCRIPTION

SSH/SFTP client module.

ct_ssh uses the OTP ssh application and more detailed information about e.g. functions, types and options can be found in the documentation for this application.

The Server argument in the SFTP functions should only be used for SFTP sessions that have been started on existing SSH connections (i.e. when the original connection type is ssh). Whenever the connection type is sftp, use the SSH connection reference only.

The following options are valid for specifying an SSH/SFTP connection (i.e. may be used as config elements):

        [{ConnType, Addr},
         {port, Port},
         {user, UserName}
         {password, Pwd}
         {user_dir, String}
         {public_key_alg, PubKeyAlg}
         {connect_timeout, Timeout}
         {key_cb, KeyCallbackMod}]

ConnType = ssh | sftp.

Please see ssh(3) for other types.

All timeout parameters in ct_ssh functions are values in milliseconds.

### DATA TYPES

connection() = handle() | target_name() (see module ct)
handle() = handle() (see module ct_gen_conn)

  Handle for a specific SSH/SFTP connection.

ssh_sftp_return() = term()

  A return value from an ssh_sftp function.

### EXPORTS

apread(SSH, Handle, Position, Length) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

apread(SSH, Server, Handle, Position, Length) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

apwrite(SSH, Handle, Position, Data) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

apwrite(SSH, Server, Handle, Position, Data) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

aread(SSH, Handle, Len) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

aread(SSH, Server, Handle, Len) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

awrite(SSH, Handle, Data) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

awrite(SSH, Server, Handle, Data) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

close(SSH, Handle) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

close(SSH, Server, Handle) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

connect(KeyOrName) -> {ok, Handle} | {error, Reason}

Equivalent to connect(KeyOrName, host, []).

connect(KeyOrName, ConnType) -> {ok, Handle} | {error, Reason}

Equivalent to connect(KeyOrName, ConnType, []).

connect(KeyOrName, ConnType, ExtraOpts) -> {ok, Handle} | {error, Reason}

Types:

KeyOrName = Key | Name
Key = atom()
Name = target_name() (see module ct)
ConnType = ssh | sftp | host
ExtraOpts = ssh_connect_options()
Handle = handle()
Reason = term()

Open an SSH or SFTP connection using the information associated with KeyOrName.

If Name (an alias name for Key), is used to identify the connection, this name may be used as connection reference for subsequent calls. It's only possible to have one open connection at a time associated with Name. If Key is used, the returned handle must be used for subsequent calls (multiple connections may be opened using the config data specified by Key). See ct:require/2 for how to create a new Name

ConnType will always override the type specified in the address tuple in the configuration data (and in ExtraOpts). So it is possible to for example open an sftp connection directly using data originally specifying an ssh connection. The value host means the connection type specified by the host option (either in the configuration data or in ExtraOpts) will be used.

ExtraOpts (optional) are extra SSH options to be added to the config data for KeyOrName. The extra options will override any existing options with the same key in the config data. For details on valid SSH options, see the documentation for the OTP ssh application.

See also: ct:require/2.

del_dir(SSH, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

del_dir(SSH, Server, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

delete(SSH, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

delete(SSH, Server, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

disconnect(SSH) -> ok | {error, Reason}

Types:

SSH = connection()
Reason = term()

Close an SSH/SFTP connection.

exec(SSH, Command) -> {ok, Data} | {error, Reason}

Equivalent to exec(SSH, Command, DefaultTimeout).

exec(SSH, Command, Timeout) -> {ok, Data} | {error, Reason}

Types:

SSH = connection()
Command = string()
Timeout = integer()
Data = list()
Reason = term()

Requests server to perform Command. A session channel is opened automatically for the request. Data is received from the server as a result of the command.

exec(SSH, ChannelId, Command, Timeout) -> {ok, Data} | {error, Reason}

Types:

SSH = connection()
ChannelId = integer()
Command = string()
Timeout = integer()
Data = list()
Reason = term()

Requests server to perform Command. A previously opened session channel is used for the request. Data is received from the server as a result of the command.

get_file_info(SSH, Handle) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

get_file_info(SSH, Server, Handle) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

list_dir(SSH, Path) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

list_dir(SSH, Server, Path) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

make_dir(SSH, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

make_dir(SSH, Server, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

make_symlink(SSH, Name, Target) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

make_symlink(SSH, Server, Name, Target) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

open(SSH, File, Mode) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

open(SSH, Server, File, Mode) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

opendir(SSH, Path) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

opendir(SSH, Server, Path) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

position(SSH, Handle, Location) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

position(SSH, Server, Handle, Location) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

pread(SSH, Handle, Position, Length) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

pread(SSH, Server, Handle, Position, Length) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

pwrite(SSH, Handle, Position, Data) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

pwrite(SSH, Server, Handle, Position, Data) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

read(SSH, Handle, Len) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

read(SSH, Server, Handle, Len) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

read_file(SSH, File) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

read_file(SSH, Server, File) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

read_file_info(SSH, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

read_file_info(SSH, Server, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

read_link(SSH, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

read_link(SSH, Server, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

read_link_info(SSH, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

read_link_info(SSH, Server, Name) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

receive_response(SSH, ChannelId) -> {ok, Data} | {error, Reason}

Equivalent to receive_response(SSH, ChannelId, close).

receive_response(SSH, ChannelId, End) -> {ok, Data} | {error, Reason}

Equivalent to receive_response(SSH, ChannelId, End, DefaultTimeout).

receive_response(SSH, ChannelId, End, Timeout) -> {ok, Data} | {timeout, Data} | {error, Reason}

Types:

SSH = connection()
ChannelId = integer()
End = Fun | close | timeout
Timeout = integer()
Data = list()
Reason = term()

Receives expected data from server on the specified session channel.

If End == close, data is returned to the caller when the channel is closed by the server. If a timeout occurs before this happens, the function returns {timeout,Data} (where Data is the data received so far). If End == timeout, a timeout is expected and {ok,Data} is returned both in the case of a timeout and when the channel is closed. If End is a fun, this fun will be called with one argument - the data value in a received ssh_cm message (see ssh_connection(3)). The fun should return true to end the receiving operation (and have the so far collected data returned), or false to wait for more data from the server. (Note that even if a fun is supplied, the function returns immediately if the server closes the channel).

rename(SSH, OldName, NewName) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

rename(SSH, Server, OldName, NewName) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

send(SSH, ChannelId, Data) -> ok | {error, Reason}

Equivalent to send(SSH, ChannelId, 0, Data, DefaultTimeout).

send(SSH, ChannelId, Data, Timeout) -> ok | {error, Reason}

Equivalent to send(SSH, ChannelId, 0, Data, Timeout).

send(SSH, ChannelId, Type, Data, Timeout) -> ok | {error, Reason}

Types:

SSH = connection()
ChannelId = integer()
Type = integer()
Data = list()
Timeout = integer()
Reason = term()

Send data to server on specified session channel.

send_and_receive(SSH, ChannelId, Data) -> {ok, Data} | {error, Reason}

Equivalent to send_and_receive(SSH, ChannelId, Data, close).

send_and_receive(SSH, ChannelId, Data, End) -> {ok, Data} | {error, Reason}

Equivalent to send_and_receive(SSH, ChannelId, 0, Data, End, DefaultTimeout).

send_and_receive(SSH, ChannelId, Data, End, Timeout) -> {ok, Data} | {error, Reason}

Equivalent to send_and_receive(SSH, ChannelId, 0, Data, End, Timeout).

send_and_receive(SSH, ChannelId, Type, Data, End, Timeout) -> {ok, Data} | {error, Reason}

Types:

SSH = connection()
ChannelId = integer()
Type = integer()
Data = list()
End = Fun | close | timeout
Timeout = integer()
Reason = term()

Send data to server on specified session channel and wait to receive the server response.

See receive_response/4 for details on the End argument.

session_close(SSH, ChannelId) -> ok | {error, Reason}

Types:

SSH = connection()
ChannelId = integer()
Reason = term()

Closes an SSH session channel.

session_open(SSH) -> {ok, ChannelId} | {error, Reason}

Equivalent to session_open(SSH, DefaultTimeout).

session_open(SSH, Timeout) -> {ok, ChannelId} | {error, Reason}

Types:

SSH = connection()
Timeout = integer()
ChannelId = integer()
Reason = term()

Opens a channel for an SSH session.

sftp_connect(SSH) -> {ok, Server} | {error, Reason}

Types:

SSH = connection()
Server = pid()
Reason = term()

Starts an SFTP session on an already existing SSH connection. Server identifies the new session and must be specified whenever SFTP requests are to be sent.

subsystem(SSH, ChannelId, Subsystem) -> Status | {error, Reason}

Equivalent to subsystem(SSH, ChannelId, Subsystem, DefaultTimeout).

subsystem(SSH, ChannelId, Subsystem, Timeout) -> Status | {error, Reason}

Types:

SSH = connection()
ChannelId = integer()
Subsystem = string()
Timeout = integer()
Status = success | failure
Reason = term()

Sends a request to execute a predefined subsystem.

write(SSH, Handle, Data) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

write(SSH, Server, Handle, Data) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

write_file(SSH, File, Iolist) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

write_file(SSH, Server, File, Iolist) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

write_file_info(SSH, Name, Info) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).

write_file_info(SSH, Server, Name, Info) -> Result

Types:

SSH = connection()
Result = ssh_sftp_return() | {error, Reason}
Reason = term()

For info and other types, see ssh_sftp(3).