Книга: Fedora™ Unleashed, 2008 edition

Using scp to Copy Individual Files Between Machines

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:

scp test.txt 10.0.0.1:

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 that 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 by simply specifying the remote file as the source and the current directory (.) as the destination:

scp 10.0.0.1:remote.txt .

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 Fedora Core Linux. If a patch is released — and we hope one is eventually — the 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.

Оглавление книги


Генерация: 1.538. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз