[No audio]
File Transfer. There are many commands
that are used to transfer files from one
computer to another. As long as your
computer is connected in the network,
you could transfer files or directories
from one server to another. Some of
those commands are FTP, which stands for
File Transfer Protocol. This is one of
the old legendary commands that are used
in many different operating system. It
is still used in Linux, Windows and Mac,
and in many other operating system this
command is used. Next one, we have SCP,
which is a Secure Copy Protocol, and
then the next one is rsync command.
This command is mostly used by system
administrator to perform files backups
from one system to another, they could
schedule those commands through cronjob
to copy all those sync, rsync files.
So let's look at a few of these commands
in our Linux environment. Here we have
our Linux machine. And I'm logged in as
myself. So when you want to copy a file,
let's say I wanted to copy a file that
is called myfirstfile, the first thing
I have to do is type ftp, and the
machine name that it is going to, which is
the destination server.
[No audio]
Okay, so as an example, to FTP, a file
from your server to another server, I
have logged into my Linux machine as
myself, and we'll see who you are,
you are yourself. So before you try to do a
transfer, just see if you could ping
Google, because without internet, you
won't be able to transfer any file. Now
I could ping Google, it means my
computer is on the network. Now, where
do we have to transfer and what do we
have to transfer. Now of course, you do
need a server that is running FTP
daemon, meaning your server, your
client, and the server that you're
trying to connect should have FTP daemon
running and the daemon name is vsftpd.
For this training, we do not have
an extra external FTP. So we will try to
connect to the Redhat FTP server just
for training purposes. So the command to
run is ftp ftp.redhat.com.
And you will see, as soon as you are
connected, it will ask you for the
password, for the username and a
password. So you provide the credentials
that are given to you by the Redhat
support. So when you enter the password
and username, then you will enter the
command put and the file name, and
that's how it will be transferred to, to
the to the FTP site. Now, if you're
trying to transfer to a server that is
not running the FTP daemon. So let's say
in our environment, we have ps -ef.
And we'll grep for ftp, and you will see
there is no FTP daemon running, right. So
as a training purpose, we will
try to trasfer FTP to our own server.
And our own server is localhost or the
name of our host, which is MyFirstLinuxOS. So first, if you
ping MyFirstLinuxOS, you will see
you are getting reply right. So
it means you are connected to your own
machine, of course, let's clear it out.
And now try to do ftp MyFirstLinuxOS,
and you hit enter, you will see it
says, connect, ftp: connect: Connection
refused. And why is that? Because my
server, or my Linux machine is not
running the daemon and the demon is the
one that listens to the incoming
traffic. So anyway, this is how you run
the ftp command and you transfer the
files, and again, the purpose of doing
FTP is if you have an issue with your
system, and you're troubleshooting it and
you involve support, whether it's Redhat,
or CentOS, or Windows or whatever
the support that you have involved, they
would ask you to send the logs and they
will give you the FTP server account
information and credentials. So you
would have to run ftp command to send logs over.
[Author typing]
The other command that we
wanted to cover is SCP. Now SCP is
basically copying a file from one
machine to another. And of course it has
S in front of it, so it means it's copying
it securely. So let's take an example of
a file that we want to transfer. Let's
see which directory we are in. We are in
our home directory. And let's say I have
a file called right here, lalaland. So
I want to take this file, copy it from
machine A to machine B. Now, of course,
we don't have machine B where we want to
transfer. So we will use our own machine
and pretend that it's a remote machine.
So the way it works is, we will do scp
lalaland, which is the file that I'm
trying to copy over. So where am I
trying to copy over? I'm trying to copy
over to another machine, remote machine.
So we are pretending the remote machine
is, which is our own machine, of course,
MyFirstLinuxOS, and then you put
colon, which is, first is the hostname
slash, where are you copying it to? So
let's say I wanted to copy it to my
home, my user directory and the
directory you want to copy to let's say
seinfeld. seinfeld is a directory I wanted
to copy that file into that folder. So
once you have that command, hit enter.
And it says could not resolve hostname
MyFirstLinuxOS. Oh, yeah, because
I have misspelled first, these are the
types of things that you probably will
have to troubleshoot. You hit enter, my
MyFirstLinuxOS, it's still not coming up.
So what we do is, we'll just take out
this part. So I'm just gonna, what I'm
going to do is, I'm going to copy this,
and I'm going to paste it, and then hit
enter. Okay, so it is saying that
connect to host myfirstlinuxos port
22: Connection refused. So it is refusing
a connection. Why is it refusing? Not
sure. But let's try to do localhost.
[Author typing]
Yes, so you put in the password, of
course, your own password because you
are logging in as yourself on the
machine as well. This is your own
password. So once you put in the
password, you will see it says lalaland
100% completed, seven bytes, and did right
and it's point five kilobytes per
second, this is the amount of time it
took to transfer. So it did transfers.
Now let's verify if seinfeld directory
has their lalaland file in it. So which
directory I'm in? I'm in home/iafzal,
let's go to seinfeld. And now ls, do
ls -ltr. And you'll see, yep,
right here. It says lalaland. There you
go. Just to confirm, let's do
/etc/hosts, myfirstlinuxos. So it has
192.168.1.14. Okay, so now I know.
So this one, I have hard coded my
hostname with 192.168.1.14, and I'm
sure why didn't work because, my IP
has probably changed by now. So it's
probably hitting some other devices in
my network. And you see, yes, now my
Linux machine is 1.13. And the
reason I was not able to connect because
1.14 is probably one of my other
laptop, or my iPad or some other device
in my home network that got that .14
IP. And when I ran the scp command, it
was actually going to that device.
Perfect. It was a very good example. Now
you guys learn as well that how
important the /etc/hosts file is.
I'll go ahead and modify that, I'll
become root, and I will do vi /etc/hosts,
and I'll just take these two
entries out. I'll just leave these two,
[Author typing]
and close. So now if you run that
command that we were trying to run
before, hit up arrow key, up arrow key, oh
no sorry, we were logged in as
ourself, right. So now when you run that
command, you will see it will give us a
prompt. There you go. See right there.
This was the one right, you hit enter.
See it's connected. The next one is rsync,
and this will tell you exactly, if I
just type rsync, it will tell
you how you can copy files. If you just
want to itemize the changes, it will
also tell you the progress of it. So
this command is used, it's a very famous
command now, and it is used by many
system engineers to do and to perform
file systems backup. Good luck.
[No audio]