This article shows how you can copy files and folders from your local machine to remote server. Also, how you can copy files and folders from the remote server to your local machine.
We will use SCP protocol for this purpose. SCP stands for Secure Copy Protocol. It’s a means of securely transferring computer files. Files can be transferred between local host and remote host, or between two remote hosts.
SCP is based on the Secure Shell (SSH) protocol.
Copy from Local to Remote
Copy a single file from Local computer to Remote Server
scp /path/of/your/local/filename username@hostname:/path/to/remote/server/folder
with a custom port number (xxxx)
scp -P xxxx /path/of/your/local/filename username@hostname:/path/to/remote/server/folder
Copy folder from Local Computer to Remote Server
-r = recursive copy (copy all the files and folders inside the specified folder)
scp -r /path/of/your/local/folder username@hostname:/path/to/remote/server/folder
with a custom port number (xxxx)
scp -r -P xxxx /path/of/your/local/folder username@hostname:/path/to/remote/server/folder
Copy from Remote to Local
Copy a single file from Remote Server to Local Computer
scp username@hostname:/path/of/remote/server/filename /path/to/local/destination/folder
with a custom port number (xxxx)
scp -P xxxx username@hostname:/path/of/remote/server/filename /path/to/local/destination/folder
Copy folder from Local Computer to Remote Server
-r = recursive copy (copy all the files and folders inside the specified folder)
scp -r username@hostname:/path/of/remote/server/folder /path/to/local/destination/folder
with a custom port number (xxxx)
scp -r -P xxxx username@hostname:/path/of/remote/server/folder /path/to/local/destination/folder
Hope this helps. Thanks.