Hi. In this lesson we are going to cover
FTP, which stands for File Transfer Protocol.
The FTP is a standard network protocol used
for the transfer of computer files, between a
client and a server on a computer network.
FTP is built on a client-server
model architecture using separate control and data
connections between the client and the server.
This is the definition that I have actually got
it from exactly from Wikipedia. In very simple words,
an FTP is a protocol that is used to
transfer a file from server A to server B.
Now, the protocol is actually a set
of rules used by computers to communicate.
So that protocol that tells the computer, hey,
this is how it should be transferred.
This is the port that you should use.
This is an encryption that you should use.
These are all defined rules that are already
built in within a computer and operating system.
For the FTP, the default FTP port is 21.
Just like for SSH, we have 22, for DNS, we have 53,
and for many other services that we run
in Linux, for FTP, we use port 21
to communicate from one server to another.
Now, for this lecture, we need two Linux machines.
If you do not have two Linux machine, I will
recommend you that you should go ahead and build another
Linux machine running CentOS, which could be exactly
the same one as you had previously.
So my first machine that I've been
using is MyFirstLinuxVM.
This is a hostname and the second machine
that I created, and I'm referring it to
as the host name as LinuxCentOS7.
It's just a name that I picked.
So anyway, I'm sure you already have MyFirstLinuxVM,
CentOS VM,
and what you need to do is to install another Linux VM.
So if I give you a quick information on the
Oracle VirtualBox, you see this is the first VM
that I was running and this is the information.
It has one gig machine, 10 gig disk space.
The second machine that I'm using as a server
also has the same specification, ten gig,
one gig, everything exactly the same.
Even I'm using the same version of CentOS as well.
But I built a second one so
we could go through this lesson. Sorry.
All right, so to put in a
graphical way, let's go into detail.
So we have a client, a server that
needs to send a file to another server.
It's called Server A,
and Server B.
And whenever you have one server trying to
connect to another server, that recipient becomes a
server and the sender becomes a client.
So it wants to send a file over FTP protocol.
Now, if this recipient server, if it's not running
any kind of listening service to receive that protocol,
then it's going to reject that transfer.
So we need to make sure that it is running FTP,
the daemon or the service or the application on that server.
And by default whenever we run it, it
will start up that service on port 21.
All right, now what is the process to
actually configure that on client and server?
So let's look at the server side first.
So here are the quick steps that we'll cover to
do the installation configuration of FTP under remote server.
After becoming a root, we'll check if
it has FTP server installed, we'll check
if you have Internet connectivity.
We'll install the vsftpd package on the server
and then we'll modify the vsftpd configuration file.
And in that file we'll
make certain configuration changes.
And these changes are here listed, we'll go over them
one by one and then we'll start the service.
We'll enable the service, it could start at boot time.
We'll stop the firewalld so the communication can
take place between server A and server B.
If you wanted to leave your firewalld up and
running, then you have to add a rule for it
to allow to accept port or traffic 21,
so traffic on port 21. You can find that online,
how to add FTP hoard on the firewalld.
And then you could disable that firewalld
if you're not using it, just disable it
so it won't start back online.
And the last step is of course, make sure
you create a user account on that FTP server
if you do not already have it.
Because that's the account we will use to
transfer file from server A to server B.
And the last part would be we we'll
install FTP client on the client server, we'll
become root, yum install ftp, become a regular user,
and then we will create a file called kruger.
Now this is just a regular file, you could
actually use any file name you like, you could
pick pizza, pasta, whatever the file name.
But if you want to be consistent staying
with me, just make a file called kruger.
Once the file is created, then we'll FTP
to the server, we'll enter our credentials, we'll
put in a bi for binary, and then
# for hash tagging it so you could see the progress.
And we'll use the command put kruger.
Once it's transferred, then we simply type it
bye to get out of that FTP process.
All right, so now let me go back to
the installation process of FTP on the server.
All right, as I said, for that I have a client,
which is my first and,
which is the very first Linux VM that I created,
and I called it MyFirstLinuxVM.
And then I have another machine that
I'm using for this lecture purpose
and then that machine
I'm calling LinuxCentOS7.
Now in this machine, once you have it built
and configured, I want you to become root.
[No audio]
By the way, I was logged in as myself.
So if I exit and I do, whoami,
you're going to see that on this server
I have already created an account iafzal.
So if you do not have
an account, during the installation you didn't create it,
go ahead and create it. If you have it, good.
Now become root. After becoming root, of
course you could do whoami,
just to confirm which users you are logged in as.
Now you need to install the FTP daemon or the
FTP service on your machine before you install it.
Check if it has already been installed.
So I would recommend you type rpm -qa, and grep for vsftpd.
This is the name of the
package that needs to be downloaded.
Okay. It is not downloaded and it has not been installed.
So I would run the command. Before I
run the command, or before I go out
on the CentOS repository to install it,
I wanted to make sure this machine that
I'm logged in right now has Internet access.
So what I'll do is simply ping www.google.com, and
you see I'm getting a response back. Perfect.
So it means I have Internet connectivity.
Now I will go ahead and do yum install vsftpd.
[No audio]
Now this command is going to the
all the repositories and it is checking,
Hey, do you have vsftpd package that
I need to download and then install?
It did go there.
It checked and it says, yes, I do have it.
And this is for architecture 64 bit.
And the version that I have, the latest one is 3.0.2.
Do you want to download?
And the size is 171K.
Yes, I do want to download.
So simply type Y and hit enter.
It's saying downloading package.
And then it says it has a
fingerprint, some information, some security information.
Is this okay?
That comes with a package. That is fine.
Go ahead and click yes.
[No audio]
Running transaction check.
Running transaction test.
It will go through the process of
fetching that package, downloading the package, installing
the package, and then verifying the installation.
And at the it will say it is completed, and verify it of course.
Now, if you run that same command, rpm -qa
and grep for vsftpd, you will see it will
show up the package that is installed. There you go.
This is the package that is installed.
So we confirmed that it has been
downloaded, and of course, it is installed.
Now we need to configure it.
So every time you hear the word configure, it means
we have to configure it on the configuration file.
The configuration file for FTP server
is /etc/vsftpd/vsftpd.conf file.
Before I modify it, I always recommend that
you make a copy of it.
So let's go to cd vsftpd, do ls -ltr,
and you will see this is the file.
Now I want you to go ahead and make a copy of that.
So cp vsftpd.conf vsftpd.conf.orig.
This is the name I usually pick to make a copy.
As it reads, it will tell me
that this is the actual original file.
[No audio]
All right, the copy of the backup has been created.
Now I need to modify that file vsftpd.conf file,
and now I have to go
through these parameters that I have listed
on my slide to modify these parameters.
The first thing is find the following lines
and make the changes as shown below.
Disable anonymous login.
So I will search for slash a-n-o-n-y-m-o-u-s, anonymous.
It took me to the first word
because I'm doing a search within vi.
It took me the first word, but this
is not the line that I'm looking for.
So I'm going to hit N to go to the next one, and there it is.
It says anonymous_enable and it is YES.
So go ahead and remove that and put
NO, because you don't want anyone else to
come into your FTP server as anonymous. Good.
Next parameters is ascii,
it's scsi, asc,
and now you have to uncomment these two lines.
upload_enable,
download_enable,
that's perfectly fine.
Now come down to where it says ftpd,
search for that.
It says ftpd_banner=
Welcome to blah FTP service. That is fine.
You could remove that, uncomment it.
Now if you want to change
to Welcome to blah FTP server,
to Welcome to my beautiful FTP server. That is fine.
You could do that.
Now the last thing it says add at the end of this file.
If you want to go to the end of this file, you have
to press Shift G and it will take you to the end.
And here I'm just going to put first
I'm going to put comment, as Local Time,
and I'm going to put in that parameters.
It says, use_localtime=YES, perfect.
These are the only configuration
changes you have to make.
I'll go ahead and save the file.
Perfect. File is saved.
Now it's time to start the vsftpd service.
And for that, we have to
use the command systemctl start vsftpd.
[No audio]
It is started. Let's check the status if it
is actually started or not.
Yes, it says Started, see active here. Beautiful.
Now I want to enable that.
So every time my system reboots, I don't have
to go back in and start that service manually
again, I want that service to
start every time the system reboots.
And for that I have to use the
command systemctl enable vsftpd, hit Enter.
And it has been enabled now. Perfect.
Now I want to disable the firewall on this server.
To disable it, I'll use the command, before
I disable, I need to stop it.
So stop firewalld.
Now, as I said earlier, if you do not want
to disable Firewall D, which I don't recommend you, I'm
disabling it because this is my lab environment.
So I'm okay, so if you're in the production
environment and you have Firewall D running, then you
need to add the rule to allow port 21
as an incoming traffic for that firewall.
Anyway, going back, let's stop the Firewall D
because I'm using my lab and I really
don't need that, it is stopped.
Now, let's check the status.
[No audio]
See right here, it says inactive, dead. Perfect.
Now, I want you to disable it.
Meaning, every time my computer reboots, I don't
want this service to start back again.
[No audio]
It is disabled. Perfect. Beautiful.
We did our work on the server side.
And the last line you're going to
see, it says user@iafzal,
if the user does not exist already. When I do exit
out of the root, and I do, whoami,
you see, I already have an account, my account.
iafzal on this machine.
So I don't need to recreate.
If you do not have the account, or if
you do not have an account that you will
be using for the FTP purpose, than I want
you to go ahead and create an account. Anyway,
so, this is the configuration we
followed on the FTP server.
Now we have to do a few things on the FTP client.
So the client needs to install FTP the package.
And to do that, let's go in to our client.
And my client is right here.
This is MyFirstLinuxVM. Perfect.
Now, here, if I become root,
[No audio]
by the way, I was logged in as iafzal.
So now, if I run FTP command, you
see it says bash : ftp: command now found....
The reason it is not found, because I
do not have the FTP client installed.
So I need to install the client.
Now, of course, as I said, always check
to make sure you have Internet connectivity.
And for that, ping, any website that you like online.
And it says, I am getting the response back. Perfect.
Now, I could go ahead and do yum install ftp. Now,
this is not the vsftpd.
This is FTP.
So, we are installing the client
part here, not the server package.
All right. So, once you do yum install ftp, it
will go online, check for the package.
And it says Running transaction check. Package
this will be installed. Perfect.
This is what I want.
The version number so and so.
And the size has been 61 k. That's perfect. Go ahead. y.
[No audio]
Okay. Transaction test succeeded.
Verifying it, installing it, verifying it,
and completed. Beautiful.
So now, if you type ftp, and just simply hit Enter.
You see, it actually took that command and
it brought you into the FTP interactive session.
You don't want to use that right now.
Just click bye so you could get
out and get your prompt back.
Now, I want you to become iafzal again.
You could do su - iafzal,
or of course, in this case, it's yourself,
or you could just simply do exit and it
will bring you back to your own user account.
All right. So if I do ls -ltr, these are the directories
and files I have right now in my home directory.
So this is home directory. Okay.
Now, I want to create a file called touch kruger.
It is created.
If you do ls -ltr you see it has zero bytes.
Right here it says zero bytes.
If you want to add something to it,
let's say, I will do ls-ltr,
I'll output that to Kruger.
Perfect. Now when you do ls -ltr now, it has total of 517 bytes.
If you do cat on kruger, you're going to
see basically the output of exactly ls -ltr.
Anyway, why did I do that? No reason.
I just wanted to have some information in that file.
You could have done vi and typed in something else
like vi kruger, like, This is my file blah blah.
Anyway, I just wanted to populate the file with
some information so it won't be zero bytes.
Now, right now it has 545 bytes. All right, beautiful.
We're moving along. Now, we have the file.
Now the question is, I want to
transfer that kruger file to the server.
Then the server is the one
where we installed that FTP package.
So in order to transfer the file over to the server,
we need to know the IP address of the server.
So I'll go back into my server,
this is my server.
For the IP address, I'll type ifconfig,
and if I move up, you're going to
see the IP address for enp0s3.
The assigned one is 192.168.1.58. Perfect.
We got the IP address.
Now I'm going to do ftp 192.168.1.58.
Hit Enter.
Beautiful. There you go.
It says, Welcome to blah FTP server.
See that blah thing?
I told you if you wanted to put
it beautiful here, it would show beautiful there.
Okay, so anyway, it says name and
IP address and the username is iafzal.
So by default, it picked the username that
I've been trying to FTP it over.
If you wanted to use a different
username, then you will specify here.
Let's say you want to use john or whatever,
but I wanted to use my own name,
so I'm not going to enter anything.
I'm going to leave it as default, and
I'm going to go ahead and hit Enter.
Please specify the password.
This is the password of your iafzal account
to that server or to that remote machine.
[No audio]
It says, 230 Login successful.
Remote system type is Unix. Using binary mode to transfer files.
Perfect. Now, what I need to do, I want you to type
bi or bin as switching to binary mode because you want
to transfer the file always using FTP through the binary mode.
That is fine.
Then I want you to type hash, hash, meaning when you
do the transfer, show me the hashtags, which will tell me
that there's a progress going on in hashtag progress.
Now time to put the file.
So when it's time to transfer, you use the command put
because you are going from A to B and do kruger.
Hit Enter.
Right here it says, as soon as you hit,
put kruger local, kruger remote, Entering Passive Mode, 150.
Okay, to send data, hashtag,
remember, this is the progress.
If it was a huge file, you
would have seen so many hashtags.
226 Transfer complete.
545 bytes sent,
this is the size of my file. 545 sent,
succeeded. Perfect.
Now you could just do bye. Now you
are back out to your machine, now
do you want to confirm on
the server if it's been transferred? Of course. Yes.
Let's go to server.
I am in my home directory nad let's do ls -ltr,
and you're going to see right here, this is kruger.
This is the file transfer.
That's how the FTP file transfer works.
I hope this lecture actually has served its purpose.
And you know how the FTP works.
If you have any questions, please
do not hesitate to contact me.
I'm here to help you.
So let's go and work this FTP
server to learn this thing together. Good luck.
[No audio]