API for using SSH in clojure.
(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"))))))
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.
(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
(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
(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-channel? channel)
Predicate used to test for a connected channel.
Predicate used to test for a connected channel.
(connected? session)
Predicate used to test for a connected session.
Predicate used to test for a connected session.
(copy-identities from-agent to-agent)
(disconnect-channel channel)
Disconnect a session.
Disconnect a session.
(exec-channel session)
Open an Exec channel in the session.
Open an Exec channel in the session.
(exit-status channel)
Return the exit status of a channel.
Return the exit status of a channel.
(fingerprint keypair)
Return a keypair's fingerprint.
Return a keypair's fingerprint.
(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.
(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
(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.
(has-identity? agent name)
Check if the given identity is present.
Check if the given identity is present.
(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.
(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
(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.
(memfn-varargs name klass)
(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
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-parse-copy cmd)
(scp-parse-times cmd)
(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
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
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.
(session-cipher-none session)
Reset the session to use no cipher
Reset the session to use no cipher
(session-hostname session)
Return the hostname for a session
Return the hostname for a session
(session-port session)
Return the port for a session
Return the port for a session
(session? x)
Predicate to test for a session
Predicate to test for a session
(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
(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 {: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)
(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.
(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-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.
(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.
(ssh-shell-proc session in {:keys [agent-forwarding pty out err] :as opts})
Run a ssh-shell.
Run a ssh-shell.
(string-stream s)
Return an input stream with content from the string s.
Return an input stream with content from the string s.
(the-session session)
Return the JSch session for the given session.
Return the JSch session for the given session.
(unforward-local-port session local-port)
Remove local port forwarding
Remove local port forwarding
(unforward-remote-port session remote-port)
Remove remote port forwarding
Remove remote port forwarding
(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.
(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-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.)
(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.)
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close