It’s time to talk about scp which stands for secure copy and allows you to securely copy files 1
and directories between two hosts using SSH. This command will copy over an ssh connection 2
and it’s very useful for a lot of things that require files to be transferred over the Network. 3
It's, in fact, the tool of choice when you want to copy files around in the network and that's mainly 4
because it uses ssh which is probably already available and it is secure as well. scp is part 5
of the openssh client package. 6
The scp command can be used in three different ways: to copy from your computer to a remote server, 7
to copy from a remote server to your computer, and to copy from a remote server to another remote server. 8
In this 3rd case, the data is transferred directly between the servers. 9
Your own computer will only tell the servers what to do. Before going into scp 10
check that you have ssh access to the remote ssh server 11
you'll copy the files to or from. 12
In this video, Ubuntu will be the server and Centoes the client. 13
And I'm checking ssh. 14
I'm checking that it works! ssh the user @ and the server IP 15
so the IP address of Ubuntu 16
and it's working, I'm not continuing. 17
Let's get started with the first example. 18
I'm copying a local file to the remote system; first I'm creating a file. 19
I'm going to copy this file. I'm writing the command and then I'll explain it to you in detail: scp 20
-P 22, the file student@ service IP address. 21
:~ so P specifies the port on which the server is listening. 22
It's the default 22, then it is not necessary to specify it. 23
Let's take a look at the second part of the command. 24
It indicates the destination; there's the username that's authenticating to the server @ and the IP address 25
of the server; it is followed by a colon and the destination directory on the server, which in this 26
case is ~ the home directory of the user, 27
of this one. Note that no space is permitted before and after t@ or before and after the : sign. 28
I'm hitting Enter; its asking for the password 29
This is the password of the student user on the server. 30
And the file was copied; let's check it on the server. 31
Look, this is the file. 32
Let's see another example! If you want to copy the file under a different name on the destination, you 33
need to specify the new file name, like this. 34
So ~/ let's seay ip_cetos.txt I'm entering the password and hitting enter and it 35
was copied. 36
Look, this is the file. 37
It's the same file. 38
If you want to copy a directory, you should add the -r option, which comes from recursive, 39
I'm creating a directory, mydir1 and I'm moving the file to that directory and I'm going to copy 40
this directory to the remote server. 41
So I'm adding the -r option, which is mandatory, and I'll change the source. 42
This is the source, the director that will be copied and the destination is ~ the home directory. 43
It was copied; let's check it on the server. 44
Look, this is the director. 45
Great! 46
Another useful option is -p, which preserves the modification and access time. 47
So I am adding p 48
This is useful. 49
Also be aware that to be able to copy files, the user that runs the scp command must have the read 50
permission on the source file and the user that authenticates, 51
so the user before the @ sign, 52
this one, must have the write permission on the destination directory on the target system. In this 53
example, the name of the user that runs the command is the same as the name of the user that authenticates 54
to the server. 55
But they could be different. 56
Be careful when copying files with the same name and location on both systems because scp will overwrite 57
the files without any warning. 58
Let's see another example! To copy a file or a directory from a remote to a local system used the remote 59
location 60
as source and the local location as destination. 61
I'm copying the password file from /etc directory on the remote server to the local machine on 62
the desktop. 63
So scp the source, which will be the remote location, student @ the ip address : and the source 64
file. I'll use a correct path on the server: etc/ password and the destination home /student /desktop. 65
And the file was copied. 66
The file is on my desktop; in fact, the colon symbol is how scp distinguishes between local and remote 67
locations. 68
If you want to copy a directory, use the -r option. 69
Just as before I copied the desktop directory from the server to the client. 70
And I'll copy it on my desktop. 71
Take care not to overwrite your original desktop directory. 72
And it was copied. On the desktop there could be another directory called desktop that was copied 73
from the server, from the Ubuntu machine. 74
This one! With scp you can also copy files between two remote systems directly. 75
You'll need to have access to both systems from the machine on which you execute the scp command. 76
And the command will be something like this: scp user1@ the IP address of the source 77
: and the path to the source file 78
then user2 the IP address of the destination : and the path to the destination directory. 79
And you'll be prompted to enter the passwords for both user 1, on the first system, and user2 on 80
the second system. 81
Note there’s also a protocol called SFTP or SSH File Transfer Protocol which like SCP uses 82
SSH for network file transfer. Compared to scp, 83
SFTP includes extra capabilities such as resuming interrupted transfers, directory listings or remote 84
file removal. 85
So SFTP is more complex than SCP, but scp is in general faster. 86
Note that SFTP has nothing to do with the classical FTP protocol. 87
There are some GUIs available for SFTP so that you can transfer files from one machine to another using 88
SFTP 89
and SSH in graphical mode. 90
A well known implementation of an SFTP client is WinSCP for Windows or FileZilla, which is a 91
crossplatform client and works on Windows, Linux and Mac. At the end 92
I'll show you how to transfer files between Windows and Ubuntu using FileZilla. 93
I'm downloading FileZilla for Windows. 94
And I'm installing it. 95
The installation process is very simple, just press next few times and finish at the end. 96
It was installed. 97
This is FileZilla. 98
Now I write the IP address of the server, 99
this is my Ubuntu VM, the username student, its password and the default 22 port, and I'm connecting 100
to the server. 101
OK, this is the server: on the right side, you see the server side. 102
I can, for example, copy this file, ip data.txt, from the server to the client, so to Windows. For example, 103
I'm going to the desktop 104
and I'm copying it 105
there using drag and drop. 106
And it was copied on my desktop. 107
This is the file. 108
You can copy a file from the client to the server in the same manner. 109
This is the file I have copied, OK, and that's all about SCP! Thank you!