The SCP protocol is a network protocol, based on the BSD RCP protocol, which supports file transfers between hosts on a network. SCP uses Secure Shell (SSH) for data transfer and uses the same mechanisms for authentication, thereby ensuring the authenticity and confidentiality of the data in transit. A client can send (upload) files to a server, optionally including their basic attributes (permissions, timestamps). Clients can also request files or directories from a server (download). SCP runs over TCP port 22 by default. Like RCP, there is no RFC that defines the specifics of the protocol. Read more here
Syntax:
$scp [arguments] source destination
-
Copy a file from remote server to the local server
$ scp usernameOfRemoteServer@IPOfRemoteServer:/path/to/file.txt /local/path/ (or) you could specify the local server address as well, which is optional
$ scp usernameOfRemoteServer@IPOfRemoteServer:/path/to/file.txt usernameOfLocalServer@IPOfLocalServer:/local/path/ -
Copy a file from local server to the remote server
$ scp /local/path/file.txt usernameOfRemoteServer@IPOfRemoteServer:/path/to/ (or) you could specify the local server address as well, which is optional
$ scp usernameOfLocalServer@IPOfLocalServer:/local/path/file.txt usernameOfRemoteServer@IPOfRemoteServer:/path/to/ -
Copy a directory from remote server to the local server
$ scp -r usernameOfRemoteServer@IPOfRemoteServer:/path/to/folder /local/path/ (or) you could specify the local server address as well, which is optional
$ scp -r usernameOfRemoteServer@IPOfRemoteServer:/path/to/folder usernameOfLocalServer@IPOfLocalServer:/local/path/ -
If your default port is not 22, Ex: if your port is 2442 , then you should add -P argument as below:
$ scp -P 2442 usernameOfRemoteServer@IPOfRemoteServer:/path/to/file.txt /local/path/