Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

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:


Click here to view code image
matthew@seymour:~$ scp test.txt 192.168.1.102:


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:


Click here to view code image
matthew@seymour:~$ scp test.txt 192.168.1.102:newtest.txt


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


Click here to view code image
matthew@seymour:~$ scp test.txt
192.168.1.102: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, as
follows:


Click here to view code image
matthew@seymour:~$ scp test.txt username 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:


Click here to view code image
matthew@seymour:~$ scp 192.168.1.102:remote.txt .


If you want to copy files from one remote machine to another remote machine
using scp, the best method is to first ssh to one of the remote machines and
then use scp from that location.


Using sftp to Copy Many Files Between Machines

Free download pdf