SSH Transfer Files Using scp
Synonyms:
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
- SSH connect using the same username without password as SSH Connect from Ubuntu said.
- Login to server A.
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 }} ~/