计算机网络/计算机科学与应用/系统/运维/开发

用户访问 FTP服务器

用户访问FTP服务器

lftp是一个功能强大的下载工具,支持FTP协议,llftp类似shell,具有命令补全、允许多个后台任务执行功能(书签、排队、镜像、断点续传)等


安装:

yum -y  install lftp


实例一:使用lftp从FTP服务器下载hosts 文件与pub目录到当前目录

[root@Linux ~]# lftp 47.93.209.191
lftp 47.93.209.191:~> ls
-rw-r--r--    1 0        0             213 Oct 17 06:31 hosts
drwxr-xr-x    2 0        0            4096 Jun 09  2021 pub
lftp 47.93.209.191:/> get hosts
213 bytes transferred                        
lftp 47.93.209.191:/> ls
-rw-r--r--    1 0        0             213 Oct 17 06:31 hosts
drwxr-xr-x    2 0        0            4096 Jun 09  2021 pub
lftp 47.93.209.191:/> mirror pub/
Total: 1 directory, 0 files, 0 symlinks                   
lftp 47.93.209.191:/> exit

注意:lftp下载文件后在退出ftp服务时,可查看下载的文件

[root@Linux ~]# ll
total 1656048
-rw-r--r--  1 root root        213 Oct 17 14:31 hosts
drwxr-xr-x  2 root root       4096 Oct 17 14:44 pub


ls命令查看所有文件与目录,get命令下载文件,mirror命令下载目录

使用wget工具也可以从ftp服务器下载文件


实例二、添加 -O 参数,将其重命名为 a.txt ,并放到/var/tmp目录下

[root@Linux test]# wget ftp://47.93.209.191/hosts -O /root/test/a.txt
--2022-10-17 14:52:34--  ftp://47.93.209.191/hosts
           => ‘/root/test/a.txt’
Connecting to 47.93.209.191:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD not needed.
==> SIZE hosts ... 213
==> PASV ... done.    ==> RETR hosts ... 
Error in server response, closing control connection.
Retrying.

错误:Error in server response, closing control connection.

Retrying.


解决办法:

1.#vim /etc/vsftpd/vsftpd.conf

2.添加:pasv_promiscuous=YES

3.保存后退出

4.[root@Linux test]# systemctl restart vsftpd


重新下载文件即可:

[root@Linux test]# wget ftp://47.93.209.191/hosts -O /root/test/a.txt
--2022-10-17 14:56:14--  ftp://47.93.209.191/hosts
           => ‘/root/test/a.txt’
Connecting to 47.93.209.191:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD not needed.
==> SIZE hosts ... 213
==> PASV ... done.    ==> RETR hosts ... done.
Length: 213 (unauthoritative)
100%[===================================================>] 213         --.-K/s   in 0s      
2022-10-17 14:56:14 (52.0 MB/s) - ‘/root/test/a.txt’ saved [213]


在/root/test/目录下查看文件a.txt

添加 "-P" 参数,可以指定存放目录

[root@Linux test]# wegt ftp://47.93.209.191/hosts -P /root/test
-bash: wegt: command not found
[root@Linux test]# wget ftp://47.93.209.191/hosts -P /root/test
--2022-10-17 15:01:00--  ftp://47.93.209.191/hosts
           => ‘/root/test/hosts’
Connecting to 47.93.209.191:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD not needed.
==> SIZE hosts ... 213
==> PASV ... done.    ==> RETR hosts ... done.
Length: 213 (unauthoritative)
100%[===================================================>] 213         --.-K/s   in 0s      
2022-10-17 15:01:00 (40.2 MB/s) - ‘/root/test/hosts’ saved [213]

添加 “-o”参数,可以将整个执行过程的信息存入某一文件,不在终端中显示

[root@Linux test]# wget ftp://47.93.209.191/hosts -O /root/test/a.txt


添加 “-q”参数,不显示任何信息

# wget  ftp://47.93.209.191/hosts -q

添加 "-m" 参数,可下载目录

# wget ftp://47.93.209.191/pub -m


本地用户访问ftp服务器,创建普通用户alice,并在用户的/home目录下创建file,密码

设置为123,在客户端使用lftp链接到ftp服务器中的alice用户

[root@Linux test]# useradd alice
[root@Linux test]# touch /home/alice/file
[root@Linux test]# echo "123" | passwd alice
[root@Linux test]# lftp alice@47.93.209.191
Password: 
lftp alice@47.93.209.191:~> ls 
ls: Login failed: 530 Login incorrect.

出现以上错误:lftp alice@47.93.209.191:~> put /etc/services

put: Login failed: 530 Login incorrect.  


解决方法:

检查vsftpd.conf文件(如:/etc/vsftpd/vsftpd.conf),查找userlist_enable项 注释或设置为no


微信小程序 https://www.javascriptcn.com/interview-weixinapp/677f48463d78df11d950b260.html

评论

^