Linux中lftp命令

Linux中lftp命令,第1张

ncftp 工具的使用

ftp 全名为 File Transfer Protocol(档案传输协定),File Transfer Protocol 主要的功用是在 TCP/IP 网路上传送档案,常见的 ftp 工具有 ,ftp gftp lftp ncftp mc proz wget 等。档案传输在系统管理及运用上十分常见,请务必学会其中一种,以下以 ncftp 示范。

##########################################################################

行前教育

ncftp 的使用方法与 command line 下的 Bash 用法相近,以下是常用指令:

cd 切换目录

mkdir 建立目录

rmdir 砍掉空目录

del 砍掉档案

get 取回档案

put 将档案放上去

##########################################################################

使用 ncftp 登入需帐号密码的 ftp server

语法为 ncftp -u USERNAME IP-address

or

语法为 ncftp -u USERNAME Hostname

##########################################################################

lloyd@alver:~$ ncftp -u lloyd 127.0.0.1

NcFTP 3.1.3 (Mar 27, 2002) by Mike Gleason (ncftp@ncftp.com).

Connecting to 127.0.0.1...

alver.coventive.com FTP server (Version 6.4/OpenBSD/Linux-ftpd-0.17) ready.

Logging in...

Password requested by 127.0.0.1 for user "lloyd".

Password required for lloyd.

Password: ## 输入密码 ##

Linux alver 2.4.18 #22 周六 8月 3 10:58:28 CST 2002 i686 unknown

Most of the programs included with the Debian GNU/Linux system are

freely redistributablethe exact distribution terms for each program

are described in the individual files in /usr/share/doc/*/copyright

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent

permitted by applicable law.

User lloyd logged in.

Logged in to 127.0.0.1.

ncftp /home/lloyd >cd DOC/ # 切换目录到 DOC

ncftp /home/lloyd/DOC >ls# 列出该目录下的档案与目录

123/ LLOYD/ tech-report.ps VCD

5_SGML/minigateway/ user_manual.pdfXRoadTerm/

i18n/ radius/user_manual.ps XRoadTerm.tar.gz

ncftp /home/lloyd/DOC >help # 线上求助

Commands may be abbreviated. 'help showall' shows hidden and unsupported

commands. 'help <command>' gives a brief description of <command>.

ascii cathelp lpage open quote site

bgget cd jobs lpwd page rename type

bgput chmod lcdlrenamepdir rhelp umask

bgstartclose lchmod lrmplsrm version

binary debug llslrmdir putrmdir

bookmark dirlmkdir ls pwdset

bookmarks getlookup mkdir quit show

ncftp /home/lloyd/DOC >get XRoadTerm.tar.gz # 以 get 取回 XRoadTerm.tar.gz 档案

XRoadTerm.tar.gz: 20.50 kB 563.41 kB/s

ncftp /home/lloyd/DOC >quit # 离开

You have not saved a bookmark for this site.

Would you like to save a bookmark to:

ftp://lloyd:PASSWORD@127.0.0.1/DOC/

Save? (yes/no) no# 要储存帐号密码当成 bookmark 使用吗?

# 建议回答 no

Not saved. (If you don't want to be asked this, "set confirm-close no")

lloyd@alver:~$ ls -l XRoadTerm.tar.gz# 回到 shell 下,查看档案是否抓回来了

-rw-r--r--1 lloydlloyd 20993 6月 24 14:19 XRoadTerm.tar.gz

lloyd@alver:~$

##########################################################################

使用 ncftp 登入提供 anonymous 的 ftp server (公众使用无须帐号密码的 ftp

server )

语法为 ncftp P-address

or

语法为 ncftp Hostname

以下以中山 ftp server 为例:

##########################################################################

lloyd@alver:~$ ncftp ftp.nsysu.edu.tw # 除了这里不同外其余用法相同

NcFTP 3.1.3 (Mar 27, 2002) by Mike Gleason (ncftp@ncftp.com).

Connecting to 140.117.11.7...

====================================================================

欢迎光临档案伺服器.

Welcome to National Sun Yat-Sen University FTP Server (ftp.nsysu.edu.tw).

右列网址提供本站档案搜寻引擎

File Search Engine on the URL

目前 FTP 部份有 289 人正在线上,最高限制 5000 人.

There are currently 289 users out of 5000 possible.

====================================================================

Only anonymous FTP is allowed here. Please login as 'ftp'.

Logging in...

========================================================================

!!!! Important Function !!!! (重要功能介绍)

o 'cd key*word' or 'cd prefix*' or 'cd *suffix' provided (case-insentive).

(例:cd freebsd 可以打成 cd fr 或 cd *sd 或 cd f*e*d 都通用,大小写都行)

========================================================================

请多多利用 <A HREF=""></A>

可以使用方便的档案搜寻引擎喔!!!!!!!!!!!!!!!!!

========================================================================

ADM.Email: ftpadm@cc.nsysu.edu.tw

Anonymous user (202.145.53.89) logged in

Unknown command

Logged in to ftp.nsysu.edu.tw.

ncftp /pub >cd Windows

ncftp /pub/Windows >ls

Collection/ Mobile@ SAC@ WindowsNT/

Demo/MsDownload/ Simtelnet/ Winsock-l/

ncftp /pub/Windows >cd Collection/

ncftp /pub/Windows/Collection >ls

CDR-Soft/Image/ MultiMedia/ Sound/

Driver/ LIB/ Network/ WWW/

ncftp /pub/Windows/Collection >quit

You have not saved a bookmark for this site.

Would you like to save a bookmark to:

ftp://ftp.nsysu.edu.tw/Windows/Collection/

Save? (yes/no) no

Not saved. (If you don't want to be asked this, "set confirm-close no")

lloyd@alver:~$

请参考,希望能帮到你。

Linux下ftp服务可以通过搭建vsftpd服务来实现,以CentOS为例,首先查看系统中是否安装了vsftpd,可以通过执行命令 rpm -qa |grep vsftpd 来查看是否安装相应的包,如果没有安装那么可以执行 yum -y install vsftpd 来安装,安装之后首先创建ftp用户,比如ftp_test,命令如下:

useradd -s /sbin/nologin -d /home/ftp_test ftp_test

目录尽量不要选择根目录下,这里是/home/ftp_test,并且ftp_test这个目录不要手动创建,否则权限会有问题,执行命令的时候会自动创建,

可以看到权限现在是对于ftp_test用户是可读可写可执行的,其他用户和组下面的都没有任何权限,现在为ftp_test用户创建密码:

passwd ftp_test

执行之后输入2次密码确认就设置好了密码

然后编辑vsftpd配置文件,位置是:vim /etc/vsftpd/vsftpd.conf

找到anonymous_enable这个配置项,默认是YES,修改成NO,表示不允许匿名用户登录

现在直接保存配置文件,执行 systemctl start vsftpd.service 启动vsftp服务,然后可以通过命令: systemctl status vsftpd.service 查看ftp服务的运行状态,现在就可以用ftp客户端进行连接了,这里用FileZilla测试,连接正常

现在基本的ftp服务就部署完了,客户端可以正常上传,下载,修改文件;但是这样有个问题就是所有的目录都暴露给客户端了,虽然客户端不能随意修改删除其余的文件,但是因为目录可见,所以总会有一些风险,所以接下来还需要配置让ftp用户只在自己的家目录下面活动,而无法查看其它任何目录,同样是打开配置文件/etc/vsftpd/vsftpd.conf,找到chroot_local_user=YES这个配置,默认是注释的,这里去掉注释,表示只让用户在自己的目录里面活动,如果只是保存这一个配置的话,用ftp连接客户端会返回500 OOPS: vsftpd: refusing to run with writable root inside chroot()的错误,即禁止运行在可写的家目录中,因为刚才ftp_test这个目录有w权限,而现在我们使用的vsftpd版本是3.0.2 属于比较新的版本,为了安全性做了一些限制,如果你此时想通过 chmod a-w /home/ftp_test 来去掉目录的写权限,那么连接成功是没问题的,但是无法上传文件了,所以网上很多说修改权限的方法是不可取的,正确的做法是应该在下面添加一行配置allow_writeable_chroot=YES表示允许对家目录的写权限,具体配置如下:

配置完这两项以后保存退出,然后执行 systemctl restart vsftpd.service 重启vsftpd服务,现在重新使用ftp连接就成功了,并且任何 *** 作也是没问题的

现在可以看到上面的路径是一个/,对于ftp用户来说也就是根目录了,只能在这个目录下 *** 作,而无法跳出这个目录

以上就是vsftpd服务的基本搭建过程,实际使用时可以分配多个用户


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7302463.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-04
下一篇2023-04-04

发表评论

登录后才能评论

评论列表(0条)

    保存