Trooper

Erlang CIHex.pm VersionHex DocsHex.pm Total DownloadsLicense: MITPaypal: DonationPatreon: Donation

Trooper is an automation and remote execution library in Erlang. It connects to remote machines via SSH, performs commands (one-off, long-polling, interactive shells with PTY allocation), transfers files via SFTP/SCP, and supports multi-hop SSH proxy tunneling.


Features


Installation

Add trooper to your rebar.config dependencies:

{deps, [
{trooper, "~> 1.2"}
]}.

Or for Elixir projects in mix.exs:

def deps do
[
{:trooper, "~> 1.2"}
]
end

Quick Examples

One-shot Command Execution

{ok, KeyData} = file:read_file("/path/to/id_rsa"),
Opts = [
{host, "remote.server.com"},
{user, "deploy"},
{id_rsa, KeyData}
],
{ok, Trooper} = trooper_ssh:start(Opts),
{ok, 0, Output} = trooper_ssh:exec(Trooper, "uname -a"),
ok = trooper_ssh:stop(Trooper).

Interactive Command with Long Polling & PTY

Opts = [
{host, "remote.server.com"},
{user, "deploy"},
{id_rsa, KeyData},
{ptty_allow, true}
],
{ok, Trooper} = trooper_ssh:start(Opts),
WorkerPid = trooper_ssh:exec_long_polling(Trooper, "bash"),
WorkerPid ! {send, "echo 'Hello Trooper'\n"},
%% Incoming responses are sent as messages to the calling process:
%% {continue, <<"Hello Trooper\n">>}
%% {exit_status, 0}
%% closed
ok = trooper_ssh:stop(Trooper).

SFTP Remote File Operations

{ok, Trooper} = trooper_ssh:start(Opts),
ok = trooper_scp:write_file(Trooper, "/tmp/config.json", <<"{\"key\":\"value\"}">>),
{ok, Content} = trooper_scp:read_file(Trooper, "/tmp/config.json"),
{ok, Files} = trooper_scp:list_dir(Trooper, "/tmp"),
ok = trooper_scp:delete(Trooper, "/tmp/config.json"),
ok = trooper_ssh:stop(Trooper).

Documentation

Full documentation is available on HexDocs.


License

This project is licensed under the terms of the MIT License.


Support & Donations

If you find this project useful, you can support its development:

Donate with PayPal