centos ftp

本文详细记录了在CentOS 7上安装和配置FTP服务器(vsftpd)的过程,包括安装、启动、设置开机启动以及创建用户。同时,介绍了FTP客户端的安装与使用方法。在遇到"No route to host"错误时,通过检查防火墙设置和端口开放进行了故障排除。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文于2018年1月12号发布在个人博客中,因为个人博客关闭,全部迁移到优快云,以下是正文:


最近在做一个项目调研,测试了一下ftp,整理记录到这里

ftp server

在CentOS 7的包管理中,ftp server的包名称为:

[root@localhost ~]# yum search vsftpd
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Loading mirror speeds from cached hostfile
* base: mirrors.sohu.com
* extras: mirrors.163.com
* updates: mirrors.163.com
=============================== N/S matched: vsftpd ===============================
vsftpd-sysvinit.x86_64 : SysV initscript for vsftpd daemon
vsftpd.x86_64 : Very Secure Ftp Daemon

Name and summary matches only, use “search all” for everything.
[root@localhost ~]#

安装

yum install -y vsftpd

看到下面的内容(0:3.0.2-22.el7不一定相同)表示安装成功:

Installed:
 vsftpd.x86_64 0:3.0.2-22.el7

Complete!

启动

默认情况下,vsftpd安装完成不会启动:

[root@localhost ~]# systemctl status vsftpd
● vsftpd.service – Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)

启动方法:

systemctl start vsftpd

再看看状态:

[root@localhost ~]# systemctl status vsftpd
● vsftpd.service – Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2018-01-11 15:22:29 PST; 6s ago
Process: 3573 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
Main PID: 3576 (vsftpd)
CGroup: /system.slice/vsftpd.service
└─3576 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

Jan 11 15:22:29 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon…
Jan 11 15:22:29 localhost.localdomain systemd[1]: Started Vsftpd ftp daemon.

关闭vsftpd:

systemctl stop vsftpd

设置开机启动

[root@localhost ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

创建用户

ftp client访问ftp server时需要使用用户名/密码的方式,用户名密码同ftp server上的OS用户名密码,创建方法:

[root@localhost ~]# useradd -m ftpclient
[root@localhost ~]# passwd ftpclient 
Changing password for user ftpclient.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

ftp client

安装

在CentOS 7的包管理中,ftp client包名称为:

ftp.x86_64 : The standard UNIX FTP (File Transfer Protocol) client

安装:

yum install -y ftp

验证:

[root@localhost ~]# whereis ftp
ftp: /usr/bin/ftp /usr/share/man/man1/ftp.1.gz

使用

本文测试使用两台虚拟机:

192.168.120.130: 安装了vsftpd,作为ftp server
192.168.120.131: 安装了ftp,作为ftp client

登录ftp server:

[root@localhost ~]# ftp 192.168.120.130
Connected to 192.168.120.130 (192.168.120.130).
220 (vsFTPd 3.0.2)
Name (192.168.120.130:root): ftpclient
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

查看当前目录:

ftp> pwd
257 "/home/ftpclient"
ftp> ls
227 Entering Passive Mode (192,168,120,130,227,109).
150 Here comes the directory listing.
226 Directory send OK.
ftp>

上传文件:

ftp> put /home/hello.txt ~/hello.txt
local: /home/hello.txt remote: ~/hello.txt
227 Entering Passive Mode (192,168,120,130,103,97).
150 Ok to send data.
226 Transfer complete.
40 bytes sent in 9.8e-05 secs (408.16 Kbytes/sec)
ftp> ls
227 Entering Passive Mode (192,168,120,130,114,12).
150 Here comes the directory listing.
-rw-r--r-- 1 1001 1001 40 Jan 13 23:26 hello.txt
226 Directory send OK.
ftp>

下载文件:

ftp> ls
227 Entering Passive Mode (192,168,120,130,90,75).
150 Here comes the directory listing.
-rw-r--r-- 1 1001 1001 40 Jan 13 23:26 hello.txt
-rw-rw-r-- 1 1001 1001 39 Jan 13 23:28 server.txt
226 Directory send OK.
ftp> get server.txt /home/server.txt
local: /home/server.txt remote: server.txt
227 Entering Passive Mode (192,168,120,130,136,226).
150 Opening BINARY mode data connection for server.txt (39 bytes).
226 Transfer complete.
39 bytes received in 6.2e-05 secs (629.03 Kbytes/sec)
ftp>

未解决问题

No route to host

ftp连接server时报错:“ftp: connect: No route to host”,网上说需要打开vsftpd的21/tcp端口:

firewall-cmd --zone=public --permanent --add-port=21/tcp
firewall-cmd --reload

在尝试登录,可以成功,但执行部分命令仍然报错:“ftp: connect: No route to host”

暂时关闭firewall来规避该问题:

systemctl stop firewalld
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值