SCP

Transfer files and directories using the SCP protocol

The SCP transport allows transfer of files and directories from the localhost to a remote host or from a remote host to the localhost.

The SCP transport uses the SSH private key defined at the job or host level.

copy

Unlike the move verb, copy preserves the input resource during the transfer. It also means that subsequent agents will assume the resource is still located on the original host.

Copy a file

host "remote", hostname: "host.example.com", private_key: "~/.ssh/electric_sheep_rsa"

job "daily-report" do
  resource "file", path: "/var/daily/report", host: "remote"
  copy to: "localhost", using: "scp", as: "operator"
end

Recursively copy a directory

host "app", hostname: "app.example.com", private_key: "~/.ssh/electric_sheep_rsa"

job "user-uploads" do
  resource "directory", path: "/var/www/uploads", host: "app"
  copy to: "localhost", using: "scp", as: "operator"
end

In most cases, you'd better create an archive containing a copy of the directory (see Files & Directories compression) and move it as a single file than to recursively copy directories.

move

❗️

Destructive action

Unlike the copy verb, move destroys the input resource once the file or directory has been copied to the target host.

Move a file

host "remote", hostname: "host.example.com", private_key: "~/.ssh/electric_sheep_rsa"

job "daily-report" do
  resource "file", path: "/var/daily/report", host: "remote"
  move to: "localhost", using: "scp", as: "operator"
end

Recursively move a directory

host "app", hostname: "app.example.com", private_key: "~/.ssh/electric_sheep_rsa"

job "log-archives" do
  resource "directory", path: "/var/log/archives", host: "app"
  move to: "localhost", using: "scp", as: "operator"
end

Options

OptionDescription
asThe user account to use when opening the SSH/SCP connection to the remote hostRequired: yes
toThe target host: localhost or an existing remote hostRequired: yes