back

upload

upload files to remote systems

Overview

  • This module uploads files from the local machine to the remote machine.

  • Files are verified with md5 checksums before transfer and files that are already present and intact on the remote machine are not recopied.

  • Use the download module to gather files from remote filesystem to the local machine.

Form

(upload options)

Arguments

options

A hashmap of options. All available option keys and their values are described below

Options

OptionDescription
:src
type string

    A path to a file or directory on the local machine that you want to copy to the remote machine.

    If this option is specified then :content cannot be specified.

    If this path is a directory the :recurse must be true.

:content
type stringbytearrayfile

    Some content to upload to a file. Can be a String, a java.io.File object or a byte array.

    If this option is specified then :src cannot be specified.

:dest
type string

    The destination path to copy the file or directory into.

    If :recurse is true and :dest path ends in a slash; indicates that destination is a directory and the contents of :src are to be copied into the directory.

    If :recurse is true and :dest path does not end in a slash; indicates that the :src directory is to be copies as the specified path.

:owner
type integerstring

    Make the destination file or files owned by this user.

    Can be specified as a username or as a uid.

:group
type integerstring

    Make the destination file or files owned by this group.

    Can be specified as a group name or as a gid.

:mode
type integerstring

    Set the access mode of this file or files.

    Can be specified as an octal value of the form 0xxx, as a decimal value, or as a change string as is accepted by the system chmod command (eg. "u+rwx").

:attrs
type string

    Set the file or files special attributes.

    Provide as a string that is accepted to the chattr shell command

:dir-mode
type integerstring

    When doing a recursive copy, set the access mode of directories to this mode.

    Can be specified as an octal value of the form 0xxx, as a decimal value, or as a change string as is accepted by the system chmod command (eg. "u+rwx").

:preserve
type boolean

    Preserve the access mode and file timestamps of the original source file.

:recurse
type boolean

    Perform a recursive copy to transfer the entire directory contents

:force
type boolean

    Force the copy operation to overwrite other content.

    If the destination path already exists as a file, and the upload is to recursively copy a directory, delete the destination file before copying the directory.

Examples

Copy a local file to the destination server

(upload {:src "./project.clj"
         :dest "/tmp/project.clj"
         :owner "john"
         :group "users"
         :mode 0755
         :dir-mode 0644})

Recursively copy parent directory to the destination server preserving file permissions

(upload {:src "../"
         :dest "/tmp/folder-path"
         :recurse true
         :preserve true})

Alternative way to copy a file to the server

(upload {:content (clojure.java.io/file "/usr/local/bin/spire")
         :dest "/usr/local/bin/"
         :mode "a+x"})

Render a template and place it on the server

(upload {:content (selmer "nginx.conf" (edn "webserver.edn"))
         :dest "/etc/nginx/nginx.conf"})

Create a binary file on the server from a byte array

(upload {:content (byte-array [0x01 0x02 0x03 0x04])
         :dest "small.bin"})