Examples of how to use Secure Copy – SCP on a unix system
SCP – Secure Copy Explained
Secure copy or scp is a popular way to copy files to, from or between different servers over a secure and encrypted network connection. Because on most servers there is no GUI installed you’ll have to manage your servers using the command line. Secure copy is one great tool to add to your existing toolset for managing, transferring or copying files to, from or between your servers.
Here are some examples how to use secure copy on a unix operating system like Linux, OS X and many more. In the examples I use example.com as the remote hoste note that you’ll have to change this to either your server hostname or IP Address. The same goes for username, directories and the port number. I tried to make the example directories as understandable as possible. If you have any questions regarding these examples don’t hesitate to ask.
Copy file from a remote host to the local host
If you want to copy a file from a remote host to your local machine in a specific directory here’s how:
scp [email protected]:/some/remote/direcotry/transer.txt /some/local/directory
Copy file from local host to a remote host
You can also copy a file from your local machine to a remote host:
scp transfer.txt [email protected]:/some/remote/directory
Copy a directory from the local host to a remote host
To copy a directory from you can use the -r parameter. This will recursively include all the files inside that directory to be copied.
scp -r some_directory [email protected]:/some/remote/directory/
Copy from remote host to remote host
With secure copy you can also transfer files or folders between remote hosts.
scp [email protected]:/some/remote/directory/transfer.txt [email protected]:/some/remote/directory/
Copy multiple files from the local host to your home directory on the remote host
If you want to copy multiple files with one command you can just enter all the files you wan to copy to your remote host delimited with a space.
scp transfer1.txt transfer2.txt [email protected]:~
Copy from remote host to your current working directory
You can copy the file from a remote host in your working directory using the a dot (.).
scp [email protected]:/some/remote/direcotry/transfer.txt .
Copy from local host to a remote host using a different port number
Like all good system administrators you probably changed your default ssh port to another. You can specify a different port using the -P parameter.
scp -P 4444 transfer.txt [email protected]:/some/remote/directory
Debugging secure copy with verbose information using -v parameter
Basic scp command does not print much information. It just copies the files in the background. Sometimes you need to see what’s happening when you have an error for example. To print verbose information you have to specify the -v parameter. It can help you when you have problems with your connection, authentication and configuration.
scp -v transfer.txt [email protected]:/some/remote/directory