Using scp to Copy Individual Files Between Machines

The most basic use of the scp command is to copy a file from your current machine to a remote machine. You can do that with the following command:

The first parameter is the name of the file you want to send, and the second is the server to which you want to send it. Note that there is a colon at the end of the IP address. This is where you can specify an exact location for the file to be copied. If you have nothing after the colon, as in the previous example, scp copies the file to your home directory. As with SSH, scp prompts you for your password before copying takes place.

You can rewrite the previous command so you copy test.txt from the local machine and save it as newtest.txt on the server:

scp test.txt 10.0.0.1:newtest.txt

Alternatively, if there is a directory where you want the file to be saved, you can specify it like this:

scp test.txt 10.0.0.1:subdir/stuff/newtest.txt

The three commands so far have all assumed that your username on your local machine is the same as your username on the remote machine. If this is not the case, you need to specify your username before the remote address, like this:

scp test.txt [email protected]:newtest.txt

You can use scp to copy remote files locally, simply by specifying the remote file as the source and the current directory (.) as the destination:

The scp command is nominally also capable of copying files from one remote machine to another remote machine, but this functionality has yet to be properly implemented in Ubuntu. If a patch is releasedand we hope one is eventuallythe correct command to use would be this:

scp 10.0.0.1:test.txt 10.0.0.2:remotetest.txt

That copies test.txt from 10.0.0.1 to remotetest.txt on 10.0.0.2. If this works, you are asked for passwords for both servers.

Was this article helpful?

0 0

Post a comment