(defn sftp
"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
"
[session-or-hostname cmd & args]
(let [opts (parse-args args)
channel-given (instance? com.jcraft.jsch.ChannelSftp session-or-hostname)
session-given (instance? com.jcraft.jsch.Session session-or-hostname)
session (if session-given
session-or-hostname
(if channel-given
nil
(default-session
session-or-hostname
(opts :username)
(opts :port)
(opts :password))))
channel (if channel-given
session-or-hostname
(ssh-sftp session))]
(try
(when (and session (not (connected? session)))
(connect session))
(let [result (ssh-sftp-cmd channel cmd (opts :cmd) (dissoc opts :cmd))]
(if (opts :return-map)
{:exit (first result) :out (second result)}
result))
(finally
(when-not channel-given
(disconnect channel))
(when-not (or session-given channel-given)
(disconnect session))))))
Used in 0 other vars
Comments top
No comments for sftp. Log in to add a comment.