Copy Files Using SCP Command
Command format: scp -r file origin destination
Important
Make sure you have the right credentials for every remote server you are working. You need the right pair of username and password of each machine for a successful transfer.
Copy files from Origin Server to Destination Server
Scenario: You have a folder named copy_this
located at the home of origin_user
and you need to copy it and all its contents to the home of destination_user
.
Login to Origin Server and issue this command
scp -r copy_this destination_user@destination_ip_address:~/
The code above will copy the folder named copy_this
to the home folder of destination_user
. If you wish to copy copy_this
to a different location of Destination Server, replace the ~/ with the proper directory.
Example is...
sudo scp -r copy_this destination_user@destination_ip_address:/var/www/my_site/
.
Notice the sudo
at the start of the code.
With scp
, you don't actually need to login to the Origin Server to do the transfer.
scp -r origin_user@origin_ip_address:~/copy_this destination_user@destination_ip_address:~/
Upload files from local machine to a remote server
Scenario: You have in your local machine a folder named upload_this
and you need to upload it, and all files inside it, to a remote machine.
From your Terminal, cd
first to the location containing the upload_this
folder. Issue this command to do the upload.
scp -r upload_this username@remote_ip_address:~/
Download files from a remote server to a local machine
Scenario: You have in your remote server a folder named download_this
located at the home directory of the user and you need to download it, and all files inside it, to your local machine.
scp -r username@remote_ip_address:~/download_this ~/Downloads