FTP stands for File Transfer Protocol. It was written by Abhay Bhushan and published in 1971. FTP is supported by all the operating systems and browsers.
It is a client-server based protocol.
How FTP works
Step a: Client connects to server on port 21.
Step b: Server responds and ask for authentication.
Step c: Client decides weather to connect passively or actively and authenticate with credentials(user name password).
Step d: If it is an active connection, server opens port 20 for data transfer and gives ftp prompt after successful authentication.
Step e: Client call for file and server initiates file transfer.
Following picture shows a simple way of data transfer through ftp.Before setting up FTP server we have to clear our self about active and passive ftp
Why FTP uses two ports
As we already discussed FTP uses 21 port for control and 20 for data transfer, this is because of many reasons such as
- Separate data transfer path so that you can still use control port do some communication with server.
- Can initiate multiple data connections without control interruptions.
- Server decides when to send data which will minimize any increase of load on server.
Difference between an Active FTP and Passive FTP server
FTP is a tricky protocol which uses two ports one as command port(21) and other as data port(For active FTP it is 20 and for passive port it is grater then 10000). So it boils down to which port is used for data transfer.
We will set-up and configure ftp server in CentOS 6.7. This procedure is same for all Redhat based distributions like Centos, Fedora, Scientific Linux, Oracle Linux etc.
Installing FTP server in Centos
Step 1: We will use below host name and IP address for our test machine to setup FTP server
Server IP: 192.168.0.9
Host Name: ftp.linuxnix.com
Just edit file /etc/hosts
and add the line on bottom and save
Step 2: Install vsftpd (very secure FTP daemon) package.
#yum install vsftpd ftp
Configuring FTP server in Linux Centos
Step 3: Configure vsftpd package. We will edit /etc/vsftpd/vsftpd.conf you can do this with gedit (If installed) or vi command.
Change the line which contain anonymous_enable=YES to anonymous_enable=NO. This will permit any one to access FTP server with authentication.
Uncomment the following line
local_enable=YES allow users in
/etc/passwd to login
write_enable=YES allow users to write files. “NO” will permit only to read.
Change the line chroot_local_user=NO to chroot_local_user=YES. This will permit local user as FTP account. If you add an user, it will be treated as a FTP account as well.
The local user directory will be the FTP directory.
Save the file.
Step 4: Permit Home user to FTP account
Permit FTP account directory as user home directory.
#setsebool ftp_home_dir on
Step 5: Open firewall or IP Table update so that our FTP server is accessed through 21 port.
We can do this with one of the two ways.
a) First Way: Edit the file /etc/sysconfig/iptables and add the line (Like the picture)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
#service iptables restart
b) or Second way: Through setup command.
Than the screen will come as shown below.
Actually this will add the above line to iptables file.
Step 6: Start FTP service once you do all the above edit’s.
#service vsftpd start
To enable this service at boot time, you have to execute below chkconfig command.
#chkconfig vsftpd on
Step 7: Now the FTP server is live. We can check with ftp command. Just create a test account to do the testing.
Changing password for user rejaul. New password: <Enter Password for user>
Now we will login to ftp
# ftp localhost Trying ::1... ftp: connect to address ::1Connection refused Trying 127.0.0.1... Connected to localhost (127.0.0.1). 220 (vsFTPd 2.2.2) Name (localhost:root): lftp ftp.linuxnix.com 331 Please specify the password. Password: <Enter Password for user> 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files.
Now FTP server is ready and you do multiple file transfers from FTP as well. You can also browse your ftp server from web browser after typing below line in address bar.
User Name and password will be asked. Than you will find the file and directory tree.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix- June 29, 2020
- FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018