pod.epiccastle.bbssh.scp
Implementation of the scp protocol
scp-from
(scp-from remote-path local-file {:keys [session recurse? preserve-mode? preserve-times? scp-command-fn], :or {preserve-mode? true, preserve-times? true, scp-command-fn identity}, :as options})
Using the scp protocol, copy a file or files from remote-path
on the remote machine to local-file
path on the local machine. remote-path
should be a string specifying the remote server file or directory path (relative to the remote user’s home directory). local-file
can be a string specifying the local destination path or a java.io.File
object. Passed in options
can contain the following keys and values:
:session
contains the connected ssh session reference.:recurse?
whentrue
perform a recursive copy. Defaults tofalse
.:preserve-mode?
whentrue
the file modes (permissions) of the destination files are set to the state of the source files. Whenfalse
files are set to the specified:mode
while directories are set to the specified:dir-mode
. Defaults totrue
.:mode
when:preserve-mode?
isfalse
this value defines the permissions flags for destination files. Should be set using an octal value literal prefixed with a zero (eg0000
for no flags or0777
for all flags). Defaults to0755
.:dir-mode
when:preserve-mode?
isfalse
this value defines the permissions flags for destination directories. Should be set using an octal value literal prefixed with a zero (eg0000
for no flags or0777
for all flags). Defaults to0644
.:preserve-times?
whentrue
the access time and the last modified time of the destination files are set to those of the source files. Whenfalse
the files will contain their default creation time stamp values. Defaults totrue
.:progress-fn
can be passed a function of arity 2 that will be repeatedly called during the copy process to provide status updates. Each buffer that is copied results in a call. For more information see below.:progress-context
can be used to set the initial progress context value which will be passed to the first invocation of the:progress-fn
callback. Defaults tonil
.:buffer-size
sets the size of the copy buffer. Larger values should provide more throughput but will result in less fine grained progress updates. Default is 256 kilobytes.:scp-command-fn
sets an optional function to preprocess the remote scp command line invocation. The function will be passed the string of the command to invoke to launch the scp remote process and should return a new string to use as the command.
The callback :progress-fn
will be called with 2 arguments. The first argument is the current :progress-context
value. The second argument is a hashmap with the keys :dest
, :offset
and :size
. :dest
will be a java.io.File
object representing the destination file in the local filesystem of the current copy. :size
will be the final size the file will be in bytes when the copy is complete. :offset
will be how much of the file copy has so far been performed in bytes. The progress-fn should return a new value for the progress-context. This will subsequently be passed as the first argument to the next call of progress-fn.
To get a better understanding of how these functions will be called try the following settings in options:
{
:progress-context 0
:progress-fn (fn [progress-context status]
(prn progress-context status)
(inc progress-context))
}
scp-to
(scp-to local-sources remote-path {:keys [session recurse? preserve-times? preserve-mode? progress-context scp-command-fn], :or {preserve-times? true, preserve-mode? true, scp-command-fn (fn [cmd] (str "sh -c 'umask 0000;" cmd "'"))}, :as options})
Using the scp protocol, copy a file, files or data from local-sources
on the local machine to remote-path
path on the remote machine. local-sources
should be a sequence of one or more sources. Each source can be a java.io.File
(either a file or a directory) or a vector of [data info-hash]
for raw data transfers. remote-path
should be a string specifying the remote destination path or a java.io.File
object (relative to the remote users home directory). Passed in options
can contain the following keys and values:
:session
contains the connected ssh session reference.:recurse?
whentrue
perform a recursive copy. Defaults tofalse
.:preserve-mode?
whentrue
the file modes (permissions) of the destination files are set to the state of the source files. Whenfalse
files are set to the specified:mode
while directories are set to the specified:dir-mode
. Defaults totrue
.:mode
when:preserve-mode?
isfalse
this value defines the permissions flags for destination files. Should be set using an octal value literal prefixed with a zero (eg0000
for no flags or0777
for all flags). Defaults to0755
.:dir-mode
when:preserve-mode?
isfalse
this value defines the permissions flags for destination directories. Should be set using an octal value literal prefixed with a zero (eg0000
for no flags or0777
for all flags). Defaults to0644
.:preserve-times?
whentrue
the access time and the last modified time of the destination files are set to those of the source files. Whenfalse
the files will contain their default creation time stamp values. Defaults totrue
.:progress-fn
can be passed a function of arity 2 that will be repeatedly called during the copy process to provide status updates. Each buffer that is copied results in a call. For more information see below.:progress-context
can be used to set the initial progress context value which will be passed to the first invocation of the:progress-fn
callback. Defaults tonil
.:buffer-size
sets the size of the copy buffer. Larger values should provide more throughput but will result in less fine grained progress updates. Default is 256 kilobytes.:scp-command-fn
sets an optional function to preprocess the remote scp command line invocation. The function will be passed the string of the command to invoke to launch the scp remote process and should return a new string to use as the command.
When using raw data transfers, the source declaration should be a vector of the form [data info-hash]
. The data
can be a string, a byte-array or an input-stream. The info-hash
must contain a :filename
that is used to specify the name of the destination file. In the case of an input-stream the size of the stream in bytes must be specified in a :size
entry in the info-hash
and must be correct (or else the scp protocol communication will fail).
The callback :progress-fn
will be called with 2 arguments. The first argument is the current :progress-context
value. The second argument is a hashmap with the keys :dest
, :offset
and :size
. :source
will be a java.io.File
object representing the source file in the local filesystem of the current copy. :size
will be the final size the file will be in bytes when the copy is complete. :offset
will be how much of the file copy has so far been performed in bytes. The progress-fn should return a new value for the progress-context. This will subsequently be passed as the first argument to the next call of progress-fn.
To get a better understanding of how these functions will be called try the following settings in options:
{
:progress-context 0
:progress-fn (fn [progress-context status]
(prn progress-context status)
(inc progress-context))
}