SCP comes in handy to copy files to a remote server from a computer or vice versa. You can also copy server files to another server.
All you need is your server’s IP address and user credentials to start copying. Here are some common SCP commands use cases.
Copy file from your computer to a remote server
scp file.zip user@hostip:/home/directory
This command will copy file.zip in your terminals present working directory to the home directory of the server.
Copy file from a remote server to your computer
scp user@hostip:/home/directory/file.zip ~/Downloads
You are copying file.zip from the server’s home directory to your local downloads folder.
SCP between two remote hosts from your computer
Another use case of the SCP command is during site migration to a new server. Zip your site’s root directory and copy it to the new server.
Provide login credentials and file paths of both servers to SCP in your computer’s terminal.
scp user@remotehost1:/home/file.zip user@remotehost2:/home
Mention transfer port
-p flag to add port of remote host
scp -p 1122 file.zip user@hostip:/home/directory
Use file compression
-C flag to enable the gzip compression in SSH transfer
scp -C localfile.zip user@hostip:/home/directory
More SCP Options
-vVerbose SCP operation
-p <port>Mention remote host port
-PSave the file’s modification and access times
-c <cipher>Specify the cipher for data encryption
So if you are still using an FTP client, use the SCP command in the terminal for a secure transfer.