FTP
- FTP(File Transfer Protocol,文件传输协议) 是 TCP/IP 协议组中的协议之一。FTP协议包括两个组成部分,其一为FTP服务器,其二为FTP客户端。其中FTP服务器用来存储文件,用户可以使用FTP客户端通过FTP协议访问位于FTP服务器上的资源。在开发网站的时候,通常利用FTP协议把网页或程序传到Web服务器上。此外,由于FTP传输效率非常高,在网络上传输大的文件时,一般也采用该协议。
默认情况下FTP协议使用TCP端口中的 20和21这两个端口,其中20用于传输数据,21用于传输控制信息。但是,是否使用20作为传输数据的端口与FTP使用的传输模式有关,如果采用主动模式,那么数据传输端口就是20;如果采用被动模式,则具体最终使用哪个端口要服务器端和客户端协商决定。
搭建FTP服务:
//安装ftp服务
[root@localhost ~]# yum -y install vsftpd
//ftp配置文件位置(不需要改动任何配置文件就可以使用)
[root@localhost ~]# ls /etc/vsftpd/vsftpd.conf
/etc/vsftpd/vsftpd.conf
//启动ftp
[root@localhost ~]# systemctl restart vsftpd
//查看ftp服务(21号端口):
[root@localhost ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2077/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1102/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1101/cupsd
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2392/sshd: xiaohg@p
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 4464/sshd: xiaohg@p
tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN 4637/sshd: xiaohg@p
tcp 0 0 127.0.0.1:6013 0.0.0.0:* LISTEN 5015/sshd: xiaohg@p
tcp 0 0 127.0.0.1:6014 0.0.0.0:* LISTEN 33301/sshd: xiaohg@
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp6 0 0 :::21 :::* LISTEN 34915/vsftpd
tcp6 0 0 :::22 :::* LISTEN 1102/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1101/cupsd
tcp6 0 0 ::1:6010 :::* LISTEN 2392/sshd: xiaohg@p
tcp6 0 0 ::1:6011 :::* LISTEN 4464/sshd: xiaohg@p
tcp6 0 0 ::1:6012 :::* LISTEN 4637/sshd: xiaohg@p
tcp6 0 0 ::1:6013 :::* LISTEN 5015/sshd: xiaohg@p
tcp6 0 0 ::1:6014 :::* LISTEN 33301/sshd: xiaohg@
tcp6 0 0 :::111 :::* LISTEN 1/systemd
udp 0 0 192.168.122.1:53 0.0.0.0:* 2077/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 33563/dhcpd
udp 0 0 0.0.0.0:67 0.0.0.0:* 2077/dnsmasq
udp 0 0 192.168.190.129:68 0.0.0.0:* 1077/NetworkManager
udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd
udp 0 0 0.0.0.0:5353 0.0.0.0:* 926/avahi-daemon: r
udp 0 0 127.0.0.1:323 0.0.0.0:* 942/chronyd
udp 0 0 0.0.0.0:34521 0.0.0.0:* 926/avahi-daemon: r
udp6 0 0 :::60315 :::* 926/avahi-daemon: r
udp6 0 0 :::111 :::* 1/systemd
udp6 0 0 :::5353 :::* 926/avahi-daemon: r
udp6 0 0 ::1:323 :::* 942/chronyd
以上操作正确完成后,修改配置文件允许匿名用户登录(默认是关闭的,这一步可以不做),修改后需要重启一下ftp服务使之生效:
此时登录成功:
可以看见ftp的目录,这个目录在服务器上的位置是在:
[root@localhost ~]# ls /var/ftp/pub/
dhcp.cap
如果这个目录下面是空的就会显示如下,添加文件后就如上显示;