How do I scp via ssh?
To copy from REMOTE to LOCAL:
scp -P 12345 user@server:/path/to/remote/file /path/to/local/file
To copy from LOCAL to REMOTE:
scp -P 12345 /path/to/local/file user@server:/path/to/remote/file
Note: The switch to specify port for scp
is -P
instead of -p
If you want to copy all files in a directory you can use wildcards like below:
scp -P 12345 user@server:/path/to/remote/dir/* /path/to/local/dir/
or even
scp -P 12345 user@server:/path/to/remote/dir/*.txt /path/to/local/dir/
You should use something like this
scp -P 12345 -p some_file [email protected]:
This will copy some_file
to your home directory on the remote server. Change the name or path by putting the alternative immediately after the :
(no space). Swap the arguments to copy back to the local system.
The -P 12345
is equivalent to your -p 12345
and the -p
flag tells scp
to maintain the timestamps and permissions for the destination file.
If you are doing this frequently I would suggest adding some config in the file ~/.ssh/config
add the following lines
Host highlabs
Hostname gateway.highlabs.co
User marcus
Port 12345
Then you can
ssh highlabs
or
scp highlabs:/path/to/file /local/path/to/file
to copy from the server
or
scp /local/path/to/file highlabs:/remote/path/to/file
to copy to the server
If you are using key auth tab completion works the whole way, For example ssh hi<tab>
will finish off the word and scp highlabs:/et<tab>
will expand to /etc after checking the files on the remote server