sftp,Lftp,Vsftp和Ftp

下列操作均在Centos7中执行

sftp基本用法以及命令

# 连接远程服务器
# -P 指定连接的端口
sftp ghl@192.168.186.134
sftp -P 22  ghl@192.168.186.134

# ls显示远程目录下的文件,可以正常添加ls 后的参数设置。
sftp> ls
1.txt  2.txt  3.txt  
sftp> ls -lrt
-rw-r--r--    1 root     root            0 Mar 21 16:27 1.txt
-rw-r--r--    1 root     root            0 Mar 21 16:27 2.txt
-rw-r--r--    1 root     root            0 Mar 21 16:27 3.txt
sftp> 

# lls显示本地目录下的文件,可以正常添加ls 后的参数设置。
sftp> lls 
test01.txt
sftp> 
sftp> 
sftp> lls -lrt
总用量 0
-rw-r--r--. 1 root root 0 3月  21 16:40 test01.txt
sftp> 

# pwd显示远程目录地址,lpwd显示本地目录地址
sftp> 
sftp> pwd
Remote working directory: /home/ghl
sftp> 
sftp> 
sftp> lpwd
Local working directory: /home/test01

# put 推送文件到远程当前目录  
sftp> put test01.txt 
Uploading test01.txt to /home/ghl/test01.txt
test01.txt                                                                                          100%    0     0.0KB/s   00:00    
sftp> 
sftp> 
sftp> ls -lrt
-rw-r--r--    1 root     root            0 Mar 21 16:27 1.txt
-rw-r--r--    1 root     root            0 Mar 21 16:27 2.txt
-rw-r--r--    1 root     root            0 Mar 21 16:27 3.txt
-rw-r--r--    1 ghl      ghl             0 Mar 21 17:16 test01.txt
sftp> 

# put 文件名 远程路径  可以推送文件到指定的远程路径
sftp> put test01.txt /home/test02
Uploading test01.txt to /home/test02/test01.txt
test01.txt                                                                                          100%    0     0.0KB/s   00:00    
sftp> 
sftp> 
sftp> ls -lrt /home/test02
-rw-r--r--    1 ghl      ghl             0 Mar 21 17:16 test01.txt
sftp> 

# put 本地文件路径/本地文件名 远程路径 可以本地指定路径的推送文件到远程目录
sftp> put /home/ghl/ghl01.txt /home/test02
Uploading /home/ghl/ghl01.txt to /home/test02/ghl01.txt
/home/ghl/ghl01.txt                                                                                 100%    0     0.0KB/s   00:00    
sftp> 

# get 文件名称   --下载当前远程目录下的文件,到当前本地目录
sftp> ls -lrt
-rw-r--r--    1 root     root            0 Mar 21 16:27 1.txt
-rw-r--r--    1 root     root            0 Mar 21 16:27 2.txt
-rw-r--r--    1 root     root            0 Mar 21 16:27 3.txt
-rw-r--r--    1 ghl      ghl             0 Mar 21 17:16 test01.txt
sftp> 
sftp> lls 
test01.txt
sftp> get 1.txt 
Fetching /home/ghl/1.txt to 1.txt
sftp> 
sftp> lls 
1.txt  test01.txt
sftp> 

#get 远程路径/文件名称 本地路径	   --下载指定远程路径下的文件,到指定的本地路径
sftp> get /home/test02/te
test01.txt  test02.txt  
sftp> get /home/test02/test02.txt /home/ghl/
Fetching /home/test02/test02.txt to /home/ghl/test02.txt
sftp> 
sftp> 
sftp> lls /home/ghl/
ghl01.txt  test02.txt
sftp> 
sftp> 

# cd切换远程目录,lcd切换本地目录

# bye 退出ftp

lftp 基本用法和命令

# -u 指定账号密码,密码明文显示不安全
lftp -u ghl,123456 sftp://192.168.186.134:22

# 不指定密码,需要后续输入密码才能登录
lftp sftp://ghl@192.168.186.134

# mirror 远程目录  --下载指定远程目录(ghl2)和目录下的文件,到本地路径
lftp ghl@192.168.186.134:~/ghl> mirror -R /home/ghl2/ 
mirror: Access failed: No such file (/home/ghl/ghl/ghl)
1 error detected
lftp ghl@192.168.186.134:~/ghl> mirror  /home/ghl/ 
Total: 1 directory, 6 files, 0 symlinks
New: 6 files, 0 symlinks
442 bytes transferred


# mirror -R 本地目录 远程目录 --上传本地指定路径下的目录(ghl)和目录下文件,到远程目录(ghl2)
lftp ghl@192.168.186.134:~/ghl> mirror  -R /home/ghl/ /home/ghl2/
Total: 2 directories, 11 files, 0 symlinks
New: 8 files, 0 symlinks
442 bytes transferred
To be removed: 0 directories, 3 files, 0 symlinks
lftp ghl@192.168.186.134:~/ghl> 

# ls 显示当前远程目录下的文件,!ls 显示当前本地目录下的文件

# pwd 显示当前远程路径,!pwd 显示当前本地路径

# cd 切换远程目录,!cd切换本地目录

vsftp和ftp

  1. 安装启动
# 查看是否安装vsftp 和 ftp
[root@localhost test02]# rpm -qa | grep ftp

# 在线安装
[root@localhost test02]# yum -y install vsftpd
[root@133test ftpuser]# yum install -y ftp

# 查看位置
[root@localhost vsftpd]# whereis vsftpd
vsftpd: /usr/sbin/vsftpd /etc/vsftpd /usr/share/man/man8/vsftpd.8.gz

#设置开机启动
[root@localhost vsftpd]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

# 启动
[root@localhost vsftpd]# systemctl start vsftpd

# 重启
[root@localhost vsftpd]# systemctl restart vsftpd

# 停止
[root@localhost vsftpd]# systemctl stop vsftpd

# 查看状态
[root@localhost vsftpd]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since 二 2022-03-22 11:01:14 CST; 4s ago
  Process: 1335 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 1336 (code=killed, signal=TERM)

3月 22 11:01:07 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon...
3月 22 11:01:07 localhost.localdomain systemd[1]: Started Vsftpd ftp daemon.
3月 22 11:01:14 localhost.localdomain systemd[1]: Stopping Vsftpd ftp daemon...
3月 22 11:01:14 localhost.localdomain systemd[1]: Stopped Vsftpd ftp daemon.
  1. 关闭selinux
#  查看selinux状态,enabled 表示开启,disabled 表示关闭。
[root@localhost vsftpd]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          disabled
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28
[root@localhost vsftpd]# 
[root@localhost ~]#  sestatus
SELinux status:                 disabled



# 修改 vi /etc/selinux/config ,将值改为修改SELINUX=disabled

# 修改前
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

# 修改后
[root@localhost vsftpd]# more /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
  1. 创建ftp用户
# 创建ftp用户,并修改密码
[root@localhost home]# useradd ftpuser -d /home/ftpuser
[root@localhost home]# 
[root@localhost home]# ls -lrt
总用量 0
drwxr-xr-x. 2 ghl     ghl      28 3月  22 10:15 test02
drwx------. 3 ghl     ghl     145 3月  22 10:18 ghl
drwx------  2 ftpuser ftpuser  62 3月  22 11:34 ftpuser
[root@localhost home]# 
[root@localhost home]# 
[root@localhost home]# 
[root@localhost home]# 
[root@localhost home]# passwd ftpuser
更改用户 ftpuser 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost home]# 

  1. 修改配置文件
# 修改配置文件,修改下列选项,如果没有就新增。
[root@localhost vsftpd]# vi /etc/vsftpd/vsftpd.conf
anonymous_enable=NO
ftpd_banner=仅授权用户。所有活动都可以被监控和报告
listen=YES

# 注释该项配置
#listen_ipv6=YES
  1. 连接测试
# ftp连接
[root@133test ~]# ftp
ftp> open 192.168.186.134
Connected to 192.168.186.134 (192.168.186.134).
220 仅授权用户。所有活动都可以被监控和报告
Name (192.168.186.134:root): ftpuser
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 
ftp> 

# ls 显示远程当前目录,!ls或nlist 显示本地当前目录
# cd 切换远程目录,lcd切换本地目录
# pwd 显示远程路径,!pwd显示本地路径
# get 下载远程文件到本地,put 上传本地文件到远程
# type 查看文件传输方式,bin 设置文件传输方式为二进制。
# mget 下载远程多个文件到本地,可以使用通配符。如: mget 文件名1 文件名2 ; mget *.txt
# mput 上传本地多个文件到远程,可以使用通配符。如: mput 文件名1 文件名2 ; mget *.txt
# prompt 上传以及下载文件时会有提示,使用该命令可以关闭提示
# bye 退出
posted @ 2022-03-22 15:57  锡杭  阅读(604)  评论(0)    收藏  举报