FTP服务器是提供文件存储和访问服务的服务器,通过ftp(文件传输协议)实现数据传输,而且FTP是仅基于TCP的服务,不支持UDP。FTP应用是一种C/S架构的应用,客户端和服务器端都需要安装相关的软件才能实现相互之间的数据传输。常见的软件套件有FileZilla,Server-U,VsFTP,Pure-FTPd ,ProFTPD等,其中VsFTP,Pure-FTPd ,ProFTPD是单纯的服务器程序,常见客户端程序有ftp,lftp。本文实验环境中采用的服务器程序是vsftp。
工作原理:
基于pam认证框架实现认证:
安装:
[root@sherry ~]# yum install vsftpd -y
启动:
[root@sherry home]# service vsftpd start
Starting vsftpd for vsftpd: [ OK ]
[root@sherry home]# ps -ef |grep vsftpd
root 85235 1 0 00:52 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf #以root启动以ftp运行
默认家目录:
[root@sherry home]# cat /etc/passwd |grep ftp
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
[root@sherry pub]# cd /var/ftp/pub
[root@sherry pub]# touch a
客户端默认登入:
[root@martin ~]# ftp 172.16.178.153
Connected to 172.16.178.153 (172.16.178.153).
220 (vsFTPd 2.2.2)
Name (172.16.178.153:root): anonymous #匿名用户
331 Please specify the password.
Password: #密码空
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (172,16,178,153,65,242).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 May 25 16:59 pub
226 Directory send OK.
ftp> cd pub
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (172,16,178,153,138,207).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 May 25 16:59 a
226 Directory send OK.
图形化操作:
创建一个ftp账号:
[root@sherry tftp]# useradd -g sherry -s /sbin/nologin -d /home/tftp testftp
登入本地账号(use lftp):
[root@martin ~]# yum install lftp -y
[root@martin ~]# lftp -u testftp,111111 172.16.178.153
lftp testftp@172.16.178.153:~> ls
-rw-r--r-- 1 0 0 0 May 25 17:59 1
-rw-r--r-- 1 501 500 0 May 25 18:02 a
lftp testftp@172.16.178.153:/> put all.sql
651585 bytes transferred
lftp指令获取:
lftp testftp@172.16.178.153:/> help
!<shell-command> (commands)
alias [<name> [<value>]] bookmark [SUBCMD]
cache [SUBCMD] cat [-b] <files>
cd <rdir> chmod [OPTS] mode file...
close [-a] [re]cls [opts] [path/][pattern]
debug [<level>|off] [-o <file>] du [options] <dirs>
exit [<code>|bg] get [OPTS] <rfile> [-o <lfile>]
glob [OPTS] <cmd> <args> help [<cmd>]
history -w file|-r file|-c|-l [cnt] jobs [-v]
kill all|<job_no> lcd <ldir>
lftp [OPTS] <site> ls [<args>]
mget [OPTS] <files> mirror [OPTS] [remote [local]]
mkdir [-p] <dirs> module name [args]
more <files> mput [OPTS] <files>
mrm <files> mv <file1> <file2>
[re]nlist [<args>] open [OPTS] <site>
pget [OPTS] <rfile> [-o <lfile>] put [OPTS] <lfile> [-o <rfile>]
pwd [-p] queue [OPTS] [<cmd>]
quote <cmd> repeat [OPTS] [delay] [command]
rm [-r] [-f] <files> rmdir [-f] <dirs>
scache [<session_no>] set [OPT] [<var> [<val>]]
site <site_cmd> source <file>
torrent [-O <dir>] <file> user <user|URL> [<pass>]
version wait [<jobno>]
zcat <files> zmore <files>