clj-libssh2.ssh

exec

(exec session-or-host commandline & {:as io})
Execute a command and get the results.

If you're executing a command and don't care about the output you should
redirect its output on the remote host to /dev/null. This function will
always read the output across the wire even if it won't be returned as this
is the only reliable way to wait for the exit status to be correctly set.

Arguments:

session-or-host  Either a valid clj-libssh2.session.Session object or a map
                 suitable for handing off to with-session.
commandline      The command which should be executed.

Optional keyword arguments:

:in  A String or an InputStream which will be fed to the standard input of
     the remote process. If you provide an InputStream which is an instance
     of PushbackInputStream you must ensure that the size of the
     PushbackInputStream equals or exceeds the :write-chunk-size for the
     session.
:out An OutputStream. The standard output of the remote process will be
     written to this stream. If this is nil, then output will be discarded.
     If this is not provided, then the output will be returned as a String.
:err An OutputStream which will be connected to the standard error of the
     remote process and in every other way behaves like :out.
:env A map of environment variables which will be set before the command is
     executed. The keys are the environment variable names. The values are
     the values for those variables. The setting of environment variables is
     controlled by the remote sshd and the value of its AcceptEnv
     configuration variable.

Return:

A map with the following keys and values.

:out     The output from standard output on the remote host. If you specify
         a (potentially nil) output stream in the arguments to this function
         then that output stream will be returned. If no output stream was
         provided then this value will be a String containing the output.
:err     The contents of standard error from the remote host, in the same
         way as :out was provided.
:exit    The exit code from the remote process.
:signal  A map with the keys :exit-signal :err-msg and :lang-tag which have
         the values from the similarly-named out arguments of
         libssh2_channel_get_exit_signal.

scp-from

(scp-from session-or-host remote-path local-path)
Retrieve a file from a remote machine using SCP.

Arguments:

session-or-host  Either a valid clj-libssh2.session.Session object or a map
                 suitable for handing off to with-session.
remote-path      The path on the remote machine of the file you wish to
                 retrieve.
local-path       The location on the local machine where the file should be
                 copied to.

Return:

A map with the following keys and values:

:local-path  The local-path argument.
:remote-path The remote-path argument.
:size        The size of the file as read.
:remote-stat A map with the following keys and values, corresponding to the
             fields in a struct stat as reported by the remote host:

             :atime  The last access time of the remote file.
             :ctime  The last time the remote file's metadata changed.
             :gid    The group ID of the remote file.
             :mode   The permission mask for the remote file.
             :mtime  The last modified time for the remote file.
             :size   The size of the file on the remote system.
             :uid    The user ID of the remote file.

Note 1:  The destination file at local-path _may_ exist even after this
         function throws an exception. It's up to the caller to handle
         partial downloads.
Note 2:  Given a return map `m` (-> m :size) and (-> m :remote-stat :size)
         should be equal. If they are not equal then steps should be taken
         to verify the download.

scp-to

(scp-to session-or-host local-path remote-path & {:keys [atime mode mtime], :as props})
Send a file to a remote machine using SCP.

Arguments:

session-or-host  Either a valid clj-libssh2.session.Session object or a map
                 suitable for handing off to with-session.
local-path       The location on the local machine where the file should be
                 copied from.
remote-path      The path on the remote machine where the file should be
                 placed.

Optional keyword arguments:

:atime The last access time which the remote file should have.
:mode  The permissions mask which should be applied to the remote file.
:mtime The last modified time which the remote file should have.

Returns:

nil

with-session

macro

(with-session session session-or-host & body)
Convenience macro for dealing with sessions.

Arguments:

session          This will be bound to a valid clj-libssh2.session.Session.
session-or-host  This is either a clj-libssh2.session.Session object (in
                 which case this macro simply binds it to session) or a map
                 describing a potential session (in which case this calls
                 clj-libssh2.session/with-session to create the session).