SSH in clojure. Uses jsch. Provides a ssh function that tries to look similar to clojure.contrib.shell/sh.
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))))))
Via maven and the clojars (http://clojars.org/clj-ssh), or Leiningen (http://github.com/technomancy/leiningen).
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)
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.
SSH agent used to manage identities.
SSH agent used to manage identities.
(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.
(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
(capitalize s)
Converts first character of the string to upper-case.
Converts first character of the string to upper-case.
(connect session)
(connect session timeout)
Connect a session.
Connect a session.
(connected? session)
Predicate used to test for a connected session.
Predicate used to test for a connected session.
(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.
(default-session-options options)
Set the default session options
Set the default session options
(exec-channel session)
Open an Exec channel in the session.
Open an Exec channel in the session.
(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.
(has-identity? name)
(has-identity? agent name)
Check if the given identity is present.
Check if the given identity is present.
(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.
(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.
(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.
(scp-sink send recv file times {:as options})
Sink scp commands to file
Sink scp commands to file
(scp-sink-file send
recv
file
mode
length
{:keys [buffer-size] :or {buffer-size 2048}})
Sink a file
Sink a file
(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.
(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.
(session-cipher-none session)
Reset the session to use no cipher
Reset the session to use no cipher
(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
(sftp-channel session)
Open a SFTP channel in the session.
Open a SFTP channel in the session.
(shell-channel session)
Open a Shell channel in the session.
Open a Shell channel in the session.
(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
(ssh-agent? object)
Predicate to test for an ssh-agent.
Predicate to test for an ssh-agent.
(ssh-exec session cmd in out opts)
Run a command via ssh-exec.
Run a command via ssh-exec.
(ssh-sftp session)
Obtain a connected ftp channel.
Obtain a connected ftp channel.
(ssh-sftp-cmd channel cmd args options)
Command on a ftp channel.
Command on a ftp channel.
(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.
(with-default-identity path & body)
Bind the default identity.
Bind the default identity.
(with-default-session-options options & body)
Set the default session options
Set the default session options
(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.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close