1. MagicESP
  2. Ubuntu Server 22.04
  3. SSH Transfer Files Using scp

SSH Transfer Files Using scp

Synonyms:
  1. scp

scp can be used to transfer files between two Ubuntu servers. It works like cp, but transfer files between servers. However, rsync is always a better choice.

Prerequisite

Transfer File

Push Single File from Server A to Server B

scp {{ file_basename }} {{ b_hostname.value }}:{{ file.value }}

Pull Single File from Server B to Server A

scp {{ b_hostname.value }}:{{ file.value }} {{ file_basename }}

Transfer Directory

Push Directory from Server A to Server B

It is very tricky, you must make sure in Server B, directory {{ get_parent(path.value) }} exists, but {{ path.value }} does not exist. {class="card-panel red-text"}

scp -r {{ path_basename }} {{ b_hostname.value }}:{{ path.value }}

Pull Directory from Server B to Server A

It is very tricky, you must make sure in Server A, directory ~/{{ path_basename }} des not exist. {class="card-panel red-text"}

scp -r {{ b_hostname.value }}:{{ path.value }} ~/