To put it another way,
- You must specify a target file. If you don’t,
scpwill fail with an error. If the target doesn’t exist,
scpwill create it. And if it does exist,
scpwill overwrite it completely without warning, so choose the name wisely.
- If the remote connection requires any port other than 22 (the default), add it after
I want to transfer a file from my local host to a remote host via port 2022
scp -P 2022 local/path/to/source/file user@remote_host:remote/path/to/target/file
I want to transfer a file from a remote host (via port 22) to my local host
scp user@remote_host:remote/path/to/source/file local/path/to/target/file
Note the lack of port declaration, as port 22 is the default.
I want to transfer a file from one remote host to another
scp source_user@source_host:path/to/source/file target_user@target_host:path/to/target/file