Liking cljdoc? Tell your friends :D

clj-ssh.ssh

SSH in clojure. Uses jsch. Provides a ssh function that tries to look similar to clojure.contrib.shell/sh.

Usage

The top level namespace is clj-ssh.ssh

(use 'clj-ssh.ssh)

There is a simple ssh function, which by default, will try and use a id_rsa key in your $HOME/.ssh directory.

(ssh hostname cmd)

Strict host key checking can be turned off.

(default-session-options {:strict-host-key-checking :no})

More advance usage is possible.

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

Installation

Via maven and the clojars (http://clojars.org/clj-ssh), or Leiningen (http://github.com/technomancy/leiningen).

License

Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)

SSH in clojure.  Uses jsch.  Provides a ssh function that tries to look
similar to clojure.contrib.shell/sh.

## Usage

The top level namespace is `clj-ssh.ssh`

    (use 'clj-ssh.ssh)

There is a simple `ssh` function, which by default, will try and use a id_rsa
key in your $HOME/.ssh directory.

    (ssh hostname cmd)

Strict host key checking can be turned off.

    (default-session-options {:strict-host-key-checking :no})

More advance usage is possible.

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

## Installation

Via maven and the clojars (http://clojars.org/clj-ssh), or
Leiningen (http://github.com/technomancy/leiningen).

## License

Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)
raw docstring

*default-identity*clj

source

*default-session-options*clj

Default SSH options

Default SSH options
sourceraw 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.
sourceraw docstring

*ssh-agent*clj

SSH agent used to manage identities.

SSH agent used to manage identities.
sourceraw docstring

add-identityclj

(add-identity)
(add-identity private-key)
(add-identity agent private-key)
(add-identity agent private-key passphrase)
(add-identity agent name private-key public-key passphrase)

Add an identity to the agent.

Add an identity to the agent.
sourceraw docstring

add-identity-with-keychainclj

(add-identity-with-keychain)
(add-identity-with-keychain private-key-path)
(add-identity-with-keychain agent private-key-path)

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
sourceraw docstring

capitalizeclj

(capitalize s)

Converts first character of the string to upper-case.

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

connectclj

(connect session)
(connect session timeout)

Connect a session.

Connect a session.
sourceraw docstring

connected?clj

(connected? session)

Predicate used to test for a connected session.

Predicate used to test for a connected session.
sourceraw docstring

create-ssh-agentclj

(create-ssh-agent)
(create-ssh-agent add-default-identity?)
(create-ssh-agent private-key passphrase?)

Create an ssh-agent. By default try and add the current user's id_rsa key.

Create an ssh-agent. By default try and add the current user's id_rsa key.
sourceraw docstring

default-identityclj

(default-identity)
source

default-sessionclj

(default-session host username port password)
source

default-session-optionsclj

(default-session-options options)

Set the default session options

Set the default session options
sourceraw docstring

disconnectclj

(disconnect session)

Disconnect a session.

Disconnect a session.
sourceraw docstring

exec-channelclj

(exec-channel session)

Open an Exec channel in the session.

Open an Exec channel in the session.
sourceraw docstring

generate-keypairclj

(generate-keypair key-type key-size passphrase)
(generate-keypair agent key-type key-size passphrase)

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.

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.
sourceraw docstring

has-identity?clj

(has-identity? name)
(has-identity? agent name)

Check if the given identity is present.

Check if the given identity is present.
sourceraw docstring

make-identityclj

(make-identity private-key-path public-key-path)
(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.
sourceraw docstring

memfn-varargscljmacro

(memfn-varargs name)
source

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.
sourceraw docstring

scp-fromclj

(scp-from session-or-hostname
          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.
sourceraw docstring

scp-parse-copyclj

(scp-parse-copy cmd)
source

scp-parse-timesclj

(scp-parse-times cmd)
source

scp-sinkclj

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

Sink scp commands to file

Sink scp commands to file
sourceraw 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
sourceraw docstring

scp-toclj

(scp-to session-or-hostname
        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.
sourceraw docstring

sessionclj

(session agent? & 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.
sourceraw docstring

session-cipher-noneclj

(session-cipher-none session)

Reset the session to use no cipher

Reset the session to use no cipher
sourceraw docstring

sftpclj

(sftp session-or-hostname cmd & args)

Execute SFTP commands.

sftp host-or-session cmd & options

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

Options are :username username to use for authentication :password password to use for authentication :port port to use if no session specified

Execute SFTP commands.

  sftp host-or-session cmd & options

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

Options are
:username   username to use for authentication
:password   password to use for authentication
:port       port to use if no session specified
sourceraw docstring

sftp-channelclj

(sftp-channel session)

Open a SFTP channel in the session.

Open a SFTP channel in the session.
sourceraw docstring

sftp-modemapclj

source

shell-channelclj

(shell-channel session)

Open a Shell channel in the session.

Open a Shell channel in the session.
sourceraw docstring

sshclj

(ssh session-or-hostname & args)

Execute commands over ssh.

ssh host-or-session cmd? & options

cmd specifies a command to exec. If no cmd is given, a shell is started and input is taken from :in.

Options are

: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. :return-map when followed by boolean true, 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) when not given or followed by false, ssh returns a vector of the remote shell's stdout followed by its stderr :username username to use for authentication :password password to use for authentication :port port to use if no session specified

Execute commands over ssh.

  ssh host-or-session cmd? & options

cmd specifies a command to exec.  If no cmd is given, a shell is started and input is taken from :in.

Options are

: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.
:return-map when followed by boolean true, 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)
            when not given or followed by false, ssh returns a vector
            of the remote shell's stdout followed by its stderr
:username   username to use for authentication
:password   password to use for authentication
:port       port to use if no session specified
sourceraw docstring

ssh-agent?clj

(ssh-agent? object)

Predicate to test for an ssh-agent.

Predicate to test for an ssh-agent.
sourceraw docstring

ssh-execclj

(ssh-exec session cmd in out opts)

Run a command via ssh-exec.

Run a command via ssh-exec.
sourceraw docstring

ssh-log-levelsclj

source

ssh-sftpclj

(ssh-sftp session)

Obtain a connected ftp channel.

Obtain a connected ftp channel.
sourceraw docstring

ssh-sftp-cmdclj

(ssh-sftp-cmd channel cmd args options)

Command on a ftp channel.

Command on a ftp channel.
sourceraw docstring

ssh-shellclj

(ssh-shell session in out opts)

Run a ssh-shell.

Run a ssh-shell.
sourceraw 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.
sourceraw docstring

with-default-identitycljmacro

(with-default-identity path & body)

Bind the default identity.

Bind the default identity.
sourceraw docstring

with-default-session-optionscljmacro

(with-default-session-options options & body)

Set the default session options

Set the default session options
sourceraw docstring

with-ssh-agentcljmacro

(with-ssh-agent [& agent] & body)

Bind an ssh-agent for use as identity manager. The argument vector can be empty, in which case a new agent is created. If passed a String or File, then this is passed to the new agent as an identity to be added. An existing agent instance can alternatively be passed.

Bind an ssh-agent for use as identity manager.
The argument vector can be empty, in which case a new agent is created.  If
passed a String or File, then this is passed to the new agent as an identity to
be added.  An existing agent instance can alternatively be passed.
sourceraw docstring

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

× close