Liking cljdoc? Tell your friends :D

clj-ssh.ssh

API for using SSH in clojure.

Usage

(use 'clj-ssh.ssh)

(let [agent (ssh-agent {})]
  (add-identity agent {:private-key-path path-to-private-key})
  (let [session (session agent hostname :strict-host-key-checking :no)]
    (with-connection session
      (let [result (ssh session {:in commands-string})]
        (println (:out result)))
      (let [result (ssh session {:cmd some-cmd-string})]
        (println (:out result))))))

(let [agent (ssh-agent {})]
  (let [session (session agent "localhost" {:strict-host-key-checking :no})]
    (with-connection session
      (let [channel (ssh-sftp session)]
        (with-channel-connection channel
          (sftp channel :cd "/remote/path")
          (sftp channel :put "/some/file" "filename"))))))
API for using SSH in clojure.

## Usage

    (use 'clj-ssh.ssh)

    (let [agent (ssh-agent {})]
      (add-identity agent {:private-key-path path-to-private-key})
      (let [session (session agent hostname :strict-host-key-checking :no)]
        (with-connection session
          (let [result (ssh session {:in commands-string})]
            (println (:out result)))
          (let [result (ssh session {:cmd some-cmd-string})]
            (println (:out result))))))

    (let [agent (ssh-agent {})]
      (let [session (session agent "localhost" {:strict-host-key-checking :no})]
        (with-connection session
          (let [channel (ssh-sftp session)]
            (with-channel-connection channel
              (sftp channel :cd "/remote/path")
              (sftp channel :put "/some/file" "filename"))))))
raw docstring

*piped-stream-buffer-size*clj

The buffer size (in bytes) for the piped stream used to implement the :stream option for :out. If your ssh commands generate a high volume of output, then this buffer size can become a bottleneck. You might also increase the frequency with which you read the output stream if this is an issue.

The buffer size (in bytes) for the piped stream used to implement
the :stream option for :out. If your ssh commands generate a high volume of
output, then this buffer size can become a bottleneck. You might also
increase the frequency with which you read the output stream if this is an
issue.
raw docstring

add-identityclj

(add-identity agent
              {:keys [name public-key private-key public-key-path
                      private-key-path identity passphrase]
               :as options})

Add an identity to the agent. The identity is passed with the :identity keyword argument, or constructed from the other keyword arguments.

:private-key A string specifying the private key :public-key A string specifying the public key :private-key-path A string specifying a path to the private key :public-key-path A string specifying a path to the public key :identity A jsch Identity object (see make-identity) :passphrase A byte array containing the passphrase

Add an identity to the agent.  The identity is passed with the :identity
keyword argument, or constructed from the other keyword arguments.

:private-key       A string specifying the private key
:public-key        A string specifying the public key
:private-key-path  A string specifying a path to the private key
:public-key-path   A string specifying a path to the public key
:identity          A jsch Identity object (see make-identity)
:passphrase        A byte array containing the passphrase
raw docstring

add-identity-with-keychainclj

(add-identity-with-keychain agent
                            {:keys [name public-key-path private-key-path
                                    identity passphrase]
                             :as options})

Add a private key, only if not already known, using the keychain to obtain a passphrase if required

Add a private key, only if not already known, using the keychain to obtain
a passphrase if required
raw docstring

asciiclj


capitalizeclj

(capitalize s)

Converts first character of the string to upper-case.

Converts first character of the string to upper-case.
raw docstring

connectclj

(connect session)
(connect session timeout)

Connect a session.

Connect a session.
raw docstring

connect-channelclj

(connect-channel channel)

Connect a channel.

Connect a channel.
raw docstring

connected-channel?clj

(connected-channel? channel)

Predicate used to test for a connected channel.

Predicate used to test for a connected channel.
raw docstring

connected?clj

(connected? session)

Predicate used to test for a connected session.

Predicate used to test for a connected session.
raw docstring

copy-identitiesclj

(copy-identities from-agent to-agent)

disconnectclj

(disconnect session)

Disconnect a session.

Disconnect a session.
raw docstring

disconnect-channelclj

(disconnect-channel channel)

Disconnect a session.

Disconnect a session.
raw docstring

exec-channelclj

(exec-channel session)

Open an Exec channel in the session.

Open an Exec channel in the session.
raw docstring

exit-statusclj

(exit-status channel)

Return the exit status of a channel.

Return the exit status of a channel.
raw docstring

fingerprintclj

(fingerprint keypair)

Return a keypair's fingerprint.

Return a keypair's fingerprint.
raw docstring

forward-local-portclj

(forward-local-port session local-port remote-port)
(forward-local-port session local-port remote-port remote-host)

Start local port forwarding. Returns the actual local port.

Start local port forwarding. Returns the actual local port.
raw docstring

forward-remote-portclj

(forward-remote-port session remote-port local-port)
(forward-remote-port session remote-port local-port local-host)

Start remote port forwarding

Start remote port forwarding
raw docstring

generate-keypairclj

(generate-keypair agent
                  key-type
                  key-size
                  passphrase
                  &
                  {:keys [comment private-key-path public-key-path]})

Generate a keypair, returned as [private public] byte arrays. Valid types are :rsa and :dsa. key-size is in bytes. passphrase can be a string or byte array. Optionally writes the keypair to the paths specified using the :private-key-path and :public-key-path keys.

Generate a keypair, returned as [private public] byte arrays.
Valid types are :rsa and :dsa.  key-size is in bytes. passphrase can be a
string or byte array.  Optionally writes the keypair to the paths specified
using the :private-key-path and :public-key-path keys.
raw docstring

has-identity?clj

(has-identity? agent name)

Check if the given identity is present.

Check if the given identity is present.
raw docstring

jump-sessionclj

(jump-session agent hosts {:keys [timeout]})

Connect via a sequence of jump hosts. Returns a session. Once the session is connected, use the-session to get a jsch Session object.

Each host is a map with :hostname, :username, :password and :port keys. All other key pairs in each host map will be passed as SSH config options.

Connect via a sequence of jump hosts.  Returns a session.  Once the
session is connected, use `the-session` to get a jsch Session object.

Each host is a map with :hostname, :username, :password and :port
keys.  All other key pairs in each host map will be passed as SSH
config options.
raw docstring

keypairclj

(keypair agent
         {:keys [public-key private-key public-key-path private-key-path comment
                 passphrase]
          :as options})

Return a KeyPair object for the given options.

:private-key A string specifying the private key :public-key A string specifying the public key :private-key-path A string specifying a path to the private key :public-key-path A string specifying a path to the public key :passphrase A byte array containing the passphrase :comment A comment for the key

Return a KeyPair object for the given options.

:private-key       A string specifying the private key
:public-key        A string specifying the public key
:private-key-path  A string specifying a path to the private key
:public-key-path   A string specifying a path to the public key
:passphrase        A byte array containing the passphrase
:comment           A comment for the key
raw docstring

make-identityclj

(make-identity agent private-key-path public-key-path)

Create a JSch identity. This can be used to check whether the key is encrypted.

Create a JSch identity.  This can be used to check whether the key is
encrypted.
raw docstring

memfn-varargscljmacro

(memfn-varargs name klass)

open-channelclj

(open-channel session session-type)

Open a channel of the specified type in the session.

Open a channel of the specified type in the session.
raw docstring

scp-fromclj

(scp-from session
          remote-paths
          local-path
          &
          {:keys [username password port mode dir-mode recursive preserve]
           :as opts})

Copy remote path(s) to local path via scp.

Options are:

:username username to use for authentication :password password to use for authentication :port port to use if no session specified :mode mode, as a 4 digit octal number (default 0644) :dir-mode directory mode, as a 4 digit octal number (default 0755) :recursive flag for recursive operation :preserve flag for preserving mode, mtime and atime. atime is not available in java, so is set to mtime. mode is not readable in java.

Copy remote path(s) to local path via scp.

Options are:

:username   username to use for authentication
:password   password to use for authentication
:port       port to use if no session specified
:mode       mode, as a 4 digit octal number (default 0644)
:dir-mode   directory mode, as a 4 digit octal number (default 0755)
:recursive  flag for recursive operation
:preserve   flag for preserving mode, mtime and atime. atime is not available
            in java, so is set to mtime. mode is not readable in java.
raw docstring

scp-parse-copyclj

(scp-parse-copy cmd)

scp-parse-timesclj

(scp-parse-times cmd)

scp-sinkclj

(scp-sink send recv file times {:as options})

Sink scp commands to file

Sink scp commands to file
raw docstring

scp-sink-fileclj

(scp-sink-file send
               recv
               file
               mode
               length
               {:keys [buffer-size] :or {buffer-size 2048}})

Sink a file

Sink a file
raw docstring

scp-toclj

(scp-to session
        local-paths
        remote-path
        &
        {:keys [username password port mode dir-mode recursive preserve]
         :as opts})

Copy local path(s) to remote path via scp.

Options are:

:username username to use for authentication :password password to use for authentication :port port to use if no session specified :mode mode, as a 4 digit octal number (default 0644) :dir-mode directory mode, as a 4 digit octal number (default 0755) :recursive flag for recursive operation :preserve flag for preserving mode, mtime and atime. atime is not available in java, so is set to mtime. mode is not readable in java.

Copy local path(s) to remote path via scp.

Options are:

:username   username to use for authentication
:password   password to use for authentication
:port       port to use if no session specified
:mode       mode, as a 4 digit octal number (default 0644)
:dir-mode   directory mode, as a 4 digit octal number (default 0755)
:recursive  flag for recursive operation
:preserve   flag for preserving mode, mtime and atime. atime is not available
            in java, so is set to mtime. mode is not readable in java.
raw docstring

sessionclj

(session agent
         hostname
         {:keys [port username password] :or {port 22} :as options})

Start a SSH session. Requires hostname. You can also pass values for :username, :password and :port keys. All other option key pairs will be passed as SSH config options.

Start a SSH session.
Requires hostname.  You can also pass values for :username, :password and :port
keys.  All other option key pairs will be passed as SSH config options.
raw docstring

session-cipher-noneclj

(session-cipher-none session)

Reset the session to use no cipher

Reset the session to use no cipher
raw docstring

session-hostnameclj

(session-hostname session)

Return the hostname for a session

Return the hostname for a session
raw docstring

session-portclj

(session-port session)

Return the port for a session

Return the port for a session
raw docstring

session?clj

(session? x)

Predicate to test for a session

Predicate to test for a session
raw docstring

sftpclj

(sftp session-or-channel {:keys [with-monitor modes] :as opts} cmd & args)

Execute SFTP commands.

sftp host-or-session options cmd & args

cmd specifies a command to exec. Valid commands are: :ls :put :get :chmod :chown :chgrp :cd :lcd :pwd :lpwd :rm :rmdir :stat :symlink

Execute SFTP commands.

  sftp host-or-session options cmd & args

cmd specifies a command to exec.  Valid commands are:
:ls
:put
:get
:chmod
:chown
:chgrp
:cd
:lcd
:pwd
:lpwd
:rm
:rmdir
:stat
:symlink
raw docstring

sftp-channelclj

(sftp-channel session)

Open a SFTP channel in the session.

Open a SFTP channel in the session.
raw docstring

sftp-modemapclj


shell-channelclj

(shell-channel session)

Open a Shell channel in the session.

Open a Shell channel in the session.
raw docstring

sshclj

(ssh session {:keys [cmd in out] :as options})

Execute commands over ssh.

Options are:

:cmd specifies a command string to exec. If no cmd is given, a shell is started and input is taken from :in. :in specifies input to the remote shell. A string or a stream. :out specify :stream to obtain a an [inputstream shell] specify :bytes to obtain a byte array or specify a string with an encoding specification for a result string. In the case of :stream, the shell can be polled for connected status.

sh returns a map of :exit => sub-process's exit code :out => sub-process's stdout (as byte[] or String) :err => sub-process's stderr (as byte[] or String)

Execute commands over ssh.

Options are:

:cmd        specifies a command string to exec.  If no cmd is given, a shell
            is started and input is taken from :in.
:in         specifies input to the remote shell. A string or a stream.
:out        specify :stream to obtain a an [inputstream shell]
            specify :bytes to obtain a byte array
            or specify a string with an encoding specification for a
            result string.  In the case of :stream, the shell can
            be polled for connected status.

sh returns a map of
              :exit => sub-process's exit code
              :out  => sub-process's stdout (as byte[] or String)
              :err  => sub-process's stderr (as byte[] or String)
raw docstring

ssh-agentclj

(ssh-agent {:keys [use-system-ssh-agent known-hosts-path]
            :or {use-system-ssh-agent true
                 known-hosts-path (str (. System getProperty "user.home")
                                       "/.ssh/known_hosts")}})

Create a ssh-agent. By default a system ssh-agent is preferred.

Create a ssh-agent. By default a system ssh-agent is preferred.
raw docstring

ssh-agent?clj

(ssh-agent? object)

Predicate to test for an ssh-agent.

Predicate to test for an ssh-agent.
raw docstring

ssh-execclj

(ssh-exec session cmd in out opts)

Run a command via ssh-exec.

Run a command via ssh-exec.
raw docstring

ssh-exec-procclj

(ssh-exec-proc session cmd {:keys [agent-forwarding pty in out err] :as opts})

Run a command via exec, returning a map with the process streams.

Run a command via exec, returning a map with the process streams.
raw docstring

ssh-log-levelsclj


ssh-sftpclj

(ssh-sftp session)

Obtain a connected ftp channel.

Obtain a connected ftp channel.
raw docstring

ssh-sftp-cmdclj

(ssh-sftp-cmd channel cmd args options)

Command on a ftp channel.

Command on a ftp channel.
raw docstring

ssh-shellclj

(ssh-shell session in out opts)

Run a ssh-shell.

Run a ssh-shell.
raw docstring

ssh-shell-procclj

(ssh-shell-proc session in {:keys [agent-forwarding pty out err] :as opts})

Run a ssh-shell.

Run a ssh-shell.
raw docstring

string-streamclj

(string-stream s)

Return an input stream with content from the string s.

Return an input stream with content from the string s.
raw docstring

the-sessionclj

(the-session session)

Return the JSch session for the given session.

Return the JSch session for the given session.
raw docstring

unforward-local-portclj

(unforward-local-port session local-port)

Remove local port forwarding

Remove local port forwarding
raw docstring

unforward-remote-portclj

(unforward-remote-port session remote-port)

Remove remote port forwarding

Remove remote port forwarding
raw docstring

utf-8clj


with-channel-connectioncljmacro

(with-channel-connection channel & body)

Creates a context in which the channel is connected. Ensures the channel is disconnected on exit.

Creates a context in which the channel is connected. Ensures the channel is
disconnected on exit.
raw docstring

with-connectioncljmacro

(with-connection session & body)

Creates a context in which the session is connected. Ensures the session is disconnected on exit.

Creates a context in which the session is connected. Ensures the session is
disconnected on exit.
raw docstring

with-local-port-forwardcljmacro

(with-local-port-forward [session local-port remote-port & [remote-host & _]]
                         &
                         body)

Creates a context in which a local SSH tunnel is established for the session. (Use after the connection is opened.)

Creates a context in which a local SSH tunnel is established for the session.
(Use after the connection is opened.)
raw docstring

with-remote-port-forwardcljmacro

(with-remote-port-forward [session remote-port local-port & [local-host & _]]
                          &
                          body)

Creates a context in which a remote SSH tunnel is established for the session. (Use after the connection is opened.)

Creates a context in which a remote SSH tunnel is established for the
session. (Use after the connection is opened.)
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close