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.
$[b_hostname]$
Transfer File
$[file]$
Push Single File from Server A to Server B
scp $file_basename$ $b_hostname$:$file$
Pull Single File from Server B to Server A
scp $b_hostname$:$file$ $file_basename$
Transfer Directory
$[path]$
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$ does not exist. {class="card-panel red-text"}
scp -r $path_basename$ $b_hostname$:$path$
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$:$path$ ~/