配置ftp并传输数据


OS version:Ubuntu18.04·
Host ip:10.10.1.123
Remote ip:10.10.1.456
目标:在Host下使用ftp,与Remote双向传输数据。

一、Host端ftp安装

sudo apt update 
sudo apt install vsftpd

二、Remote端ftp的安装、配置及启动

1. 安装

sudo apt update 
sudo apt install vsftpd

2. 配置

配置前,备份配置文件:

cp /etc/vsftpd.conf /etc/vsftpd.conf.orig 

修改配置文件:

vim /etc/vsftpd.conf

我的配置文件:

# Run standalone?  vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=NO
listen_ipv6=YES
#
# Allow anonymous FTP? (Disabled by default).
#anonymous_enable=NO
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# If enabled, vsftpd will display directory listings with the time
# in  your  local  time  zone.  The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# You may restrict local users to their home directories.  See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
chroot_local_user=YES
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd.chroot_list
#
# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
#rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
#ssl_enable=NO

# Personal add --2021.7.16
local_root=/home/vsi/tp		#自定义上传根目录
allow_writeable_chroot=YES
pasv_min_port=30000
pasv_max_port=31000
userlist_enable=YES
userlist_file=/etc/vsftpd.user_list
userlist_deny=NO

# Uncomment this to indicate that vsftpd use a utf8 filesystem.
#utf8_filesystem=YES

3. 启动并查看服务

sudo systemctl restart vsftpd
sudo systemctl status vsftpd

vsftpd服务状态

4. 打开防火墙

sudo ufw allow 20:21/tcp
sudo ufw allow 30000:31000/tcp		//vsftpd.conf对应端口
sudo ufw allow OpenSSH
sudo ufw disable
sudo ufw enable
sudo ufw status

ufw status

5. 将用户添加到允许的FTP用户列表

echo "vsi" | sudo tee -a /etc/vsftpd.user_list

三、Host端ftp实例

  1. 连接remote
~ ftp 10.10.1.456
Connected to 10.10.1.456.
220 (vsFTPd 3.0.3)
Name (10.10.1.456:cn1155): vsi
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
  1. 查看host当前目录
ftp> lcd
Local directory now /home/cn1155
  1. 向remote发送文件(put命令)
ftp> put soc.mak ftp_soc.mak
local: soc.mak remote: ftp_soc.mak
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
13610 bytes sent in 0.00 secs (216.3251 MB/s)

note: ftp_soc.mak是传输到remote上的名称(自己命名)。

  1. 从remote获取文件(get命令)
ftp> get ftp_soc.mak
local: ftp_soc.mak remote: ftp_soc.mak
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for ftp_soc.mak (13610 bytes).
226 Transfer complete.
13610 bytes received in 0.00 secs (10.9255 MB/s)
  1. 退出ftp(exit/quit命令)
ftp> quit
221 Goodbye.

NOTE:ftp不能直接传输文件夹哦。。。
解决方案:
1. 将文件夹打包后,进行传输。
2. 使用ncftp。 //未进行实验。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值