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:
:sessioncontains the connected ssh session reference.:recurse?whentrueperform a recursive copy. Defaults tofalse.:preserve-mode?whentruethe file modes (permissions) of the destination files are set to the state of the source files. Whenfalsefiles are set to the specified:modewhile directories are set to the specified:dir-mode. Defaults totrue.:modewhen:preserve-mode?isfalsethis value defines the permissions flags for destination files. Should be set using an octal value literal prefixed with a zero (eg0000for no flags or0777for all flags). Defaults to0755.:dir-modewhen:preserve-mode?isfalsethis value defines the permissions flags for destination directories. Should be set using an octal value literal prefixed with a zero (eg0000for no flags or0777for all flags). Defaults to0644.:preserve-times?whentruethe access time and the last modified time of the destination files are set to those of the source files. Whenfalsethe files will contain their default creation time stamp values. Defaults totrue.:progress-fncan 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-contextcan be used to set the initial progress context value which will be passed to the first invocation of the:progress-fncallback. Defaults tonil.:buffer-sizesets 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-fnsets 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:
:sessioncontains the connected ssh session reference.:recurse?whentrueperform a recursive copy. Defaults tofalse.:preserve-mode?whentruethe file modes (permissions) of the destination files are set to the state of the source files. Whenfalsefiles are set to the specified:modewhile directories are set to the specified:dir-mode. Defaults totrue.:modewhen:preserve-mode?isfalsethis value defines the permissions flags for destination files. Should be set using an octal value literal prefixed with a zero (eg0000for no flags or0777for all flags). Defaults to0755.:dir-modewhen:preserve-mode?isfalsethis value defines the permissions flags for destination directories. Should be set using an octal value literal prefixed with a zero (eg0000for no flags or0777for all flags). Defaults to0644.:preserve-times?whentruethe access time and the last modified time of the destination files are set to those of the source files. Whenfalsethe files will contain their default creation time stamp values. Defaults totrue.:progress-fncan 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-contextcan be used to set the initial progress context value which will be passed to the first invocation of the:progress-fncallback. Defaults tonil.:buffer-sizesets 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-fnsets 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))
}