Centos服务器搭建简单的ftp服务实践
作者:喵神星
文章介绍了在Centos服务器上搭建简单的FTP服务,并在私网客户端通过wget、curl和lftp三个工具下载FTP网页内容的过程
Centos服务器搭建简单的ftp服务
实现需求
A公网服务器:11.11.11.11
- 1、安装vsftpd服务
- 2、新增用户
- 3、添加文件
B私网客户端:192.168.1.2
- 1、安装wget、curl、以及lftp服务
- 2、通过三个工具下载文件
实现过程
A:
1、下载vsftpd服务、并且启用vsftpd服务
[root@Leep /]# yum install vsftpd -y -q
Package vsftpd-3.0.2-29.el7_9.x86_64 already installed and latest version
[root@Leep /]# systemctl start vsftpd
[root@Leep /]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2025-03-14 11:44:25 CST; 16min ago
Process: 24764 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
Main PID: 24765 (vsftpd)
CGroup: /system.slice/vsftpd.service
└─24765 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
Mar 14 11:44:25 Leep systemd[1]: Stopped Vsftpd ftp daemon.
Mar 14 11:44:25 Leep systemd[1]: Starting Vsftpd ftp daemon...
Mar 14 11:44:25 Leep systemd[1]: Started Vsftpd ftp daemon.
[root@Leep /]#
2、创建用户、并且查看用户家目录
[root@Leep /]# useradd -d /var/ftp ftpuser [root@Leep /]# cat /etc/passwd | grep ftp* ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin ftpuser:x:1000:1000::/var/ftp:/bin/bash
3、关闭系统两个防火墙
[root@Leep /]# systemctl stop firewalld && setenforce 0 setenforce: SELinux is disabled
4、在指定目录下创建文件
[root@Leep ftp]# pwd /var/ftp [root@Leep ftp]# ls 1.txt 2.txt pub [root@Leep ftp]# ll total 8 -rw-r--r-- 1 root root 4 Mar 13 15:10 1.txt -rw-r--r-- 1 root root 0 Mar 13 15:53 2.txt drwxr-xr-x 2 root root 4096 Jun 10 2021 pub [root@Leep ftp]#
B:
1、安装客户端工具
[root@TestPC /]# yum install lftp wget curl -y
2、使用curl -O 参数下载FTP网页内容
[root@TestPC /]# curl -O ftp://11.11.11.11/1.txt
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4 100 4 0 0 14 0 --:--:-- --:--:-- --:--:-- 14
您在 /var/spool/mail/root 中有新邮件
[root@TestPC /]# ls 1.txt
1.txt
[root@TestPC /]#
3、使用wget工具下载FTP网页内容
[root@TestPC /]# wget ftp://ftpuser:123@11.11.11.11/2.txt
--2025-03-14 12:11:49-- ftp://ftpuser:*password*@11.11.11.11/2.txt
=> “2.txt.1”
正在连接 11.11.11.11:21... 已连接。
正在以 ftpuser 登录 ... 登录成功!
==> SYST ... 完成。 ==> PWD ... 完成。
==> TYPE I ... 完成。 ==> 不需要 CWD。
==> SIZE 2.txt ... 完成。
==> PASV ... 完成。 ==> RETR 2.txt ... 完成。
[ <=> ] 0 --.-K/s 用时 0s
2025-03-14 12:11:49 (0.00 B/s) - “2.txt.1” 已保存 [0]
4、使用lftp工具下载FTP网页内容
[root@TestPC ftp]# lftp -u ftp 11.11.11.11 口令: lftp ftp@11.11.11.11:~> dir -rw-r--r-- 1 0 0 4 Mar 13 07:10 1.txt -rw-r--r-- 1 0 0 0 Mar 13 07:53 2.txt drwxr-xr-x 2 0 0 4096 Jun 09 2021 pub lftp ftp@11.11.11.11:/> get 1.txt 4 bytes transferred in 2 seconds (2b/s)y] lftp ftp@11.11.11.11:/> quit [root@TestPC ftp]# ls 1.txt [root@TestPC ftp]#
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
