sshkit v0.0.1 SSHKit.SSH

Provides convenience functions for working with SSH connections and executing commands on remote hosts.

Examples

{:ok, conn} = SSHKit.SSH.connect('eg.io', user: 'me')
{:ok, output, status} = SSHKit.SSH.run(conn, 'uptime')
:ok = SSHKit.SSH.close(conn)

log = fn {type, data} ->
  case type do
    :normal -> IO.write(data)
    :stderr -> IO.write([IO.ANSI.red, data, IO.ANSI.reset])
  end
end

Enum.each(output, log)
IO.puts("$?: #{status}")

Summary

Functions

Closes an SSH connection

Establishes a connection to an SSH server

Functions

close(connection)

Closes an SSH connection.

Uses SSHKit.SSH.Connection.close/1 to close the connection.

Example

:ok = SSHKit.SSH.close(conn)
connect(host, options \\ [])

Establishes a connection to an SSH server.

Uses SSHKit.SSH.Connection.open/2 to open a connection.

Example

{:ok, conn} = SSHKit.SSH.connect('eg.io', port: 2222, user: 'me', timeout: 1000)
run(connection, command, timeout \\ :infinity, ini \\ {:ok, [], nil}, handler \\ &capture/3)

Executes a command on the remote.

Using the default handler, returns {:ok, output, status} or {:error, reason}.

By default, command output is captured into a list of tuples of the form {:normal, data} or {:stderr, data}.

A custom handler function can be provided to handle channel messages.

Example

{:ok, output, status} = SSHKit.SSH.run(conn, 'uptime')