Chinaunix首页 | 论坛 | 博客
  • 博客访问: 513433
  • 博文数量: 158
  • 博客积分: 4015
  • 博客等级: 上校
  • 技术积分: 1711
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-27 14:00
文章分类

全部博文(158)

文章存档

2010年(71)

2009年(87)

我的朋友

分类: BSD

2009-09-13 10:38:22

  FreeBSD 内建有 FTP 服务器的功能,如果您要使用内建的 ftpd,我们不需要特别进行任何安装的动作,只要做好设定即可。本小节中,我们将介绍如何设定启动 FTP 服务器的功能,并进行一些基本的配置。

  二、启动 FTP 服务器

  我们有二种方式启动 ftpd,一种是使用 standalone daemon,另一种是使用 inetd。inetd 是 UNIX 系统中一个强大的「超级服务器」,我们可以使用它来管理许多系统服务,例如 telnet、ssh、ftp 等。大部份的系统服务都是使用 inetd 来启动,使用它的好处在于可以统一管理各种服务,并经由它来设定服务规则,例如是否要阻挡某些 IP 来源等。不过,使用 inetd 的方式缺点是每次有联机要求时,inetd 的 daemon 必须依联机的种类去执行相对映的指令,所以速度比较慢。

  另一种启动 FTP 的方式是使用 standalone daemon,也就是直接执行 FTP daemon,当它接收到新的联机时,就 fork() 出来处理,这种方式联机建立的速度较快,比较适合专门的 FTP 服务器。

  1、使用 inetd

  我们先来介绍如何使用 inetd 的方式启动 FTP 服务器。首先,请编辑 /etc/inetd.conf,将 ftp 设定开头的 # 移除:

ftp     stream  tcp     nowait  root    /usr/libexec/ftpd       ftpd -l
ftp stream tcp6 nowait root /usr/libexec/ftpd ftpd -l

  接下来,我们必须使用下列指令重跑 inetd:

  # kill -1 `cat /var/run/inetd.pid`(该命令基于已经运行了inetd)
如果没有运行ftp服务器,则Alt+F2里输入: inetd

  现在您就可以开始使用 FreeBSD 的 FTP 服务了。

  2、使用独立 Daemon

  如果您要以独立的 daemon 方式启动 FTP,请先确定在 inetd.conf 中没有启动 FTP 服务。接下来,请在新增一个档案 /usr/local/etc/rc.d/ftpd.sh 内容如下:

#!/bin/sh
ftpd_program="/usr/libexec/ftpd"
ftpd_flags="-D -l"
case $1 in
start)
echo "ing FTPD"
$ftpd_program $ftpd_flags
;;
stop)
echo "Stopping FTPD"
killall ftpd
;;
restart)
$0 stop
sleep 1
$0 start
;;
esac

  编辑完后,我们必须将该档案变成可执行:

  # chmod 755 /usr/local/etc/rc.d/ftpd.sh

  接下来,您就可以使用下列指令启动 FTPD 了:

  # /usr/local/etc/rc.d/ftpd.sh start

  如果您要停止 FTPD 服务,则使用下列指令:

  # /usr/local/etc/rc.d/ftpd.sh start

   三、编辑欢迎讯息

  当我们联机到一个 FTP 站台时,我们可以看到二个欢迎讯息,一个是登入前的讯息,另一个是登入后的讯息。以下列讯息为例:

# ftp localhost
Trying ::1...
Connected to localhost.alexwang.com.
220- Welcome to My FTP Server.
220-
220- This is a welcome message
220-
220- Nice to see you.
220 vmware.alexwang.com FTP server (Version 6.00LS) ready.
Name (localhost:alex):
331 Password required for alex.
Password:
230- This is the message of the day.
230-
230- It will be shown after user login.
230 User alex logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

  开头为 220- 的就是登入前的讯息,我们称它为欢迎讯息。以 230- 为开头的是登入后的讯息,我们称它为本日讯息 (Message of the day)。这二种讯息我们都可以自行设定。

  如果您要设定的是登入前的讯息,请新增一个档案 /etc/ftpwelcome,并将您的讯息写入该文件中。以下为上述范例中的讯息内容:

Welcome to My FTP Server.
This is a welcome message
Nice to see you.

  您不需要写 220- 等数据,FTP 服务器会自动帮您加上这种代码。而登入后的讯息是存放在 /etc/ftpmotd,您可以编辑该档以进行设定。

阅读(1290) | 评论(0) | 转发(0) |
0

上一篇:wget下载一个目录

下一篇:我自己写的list

给主人留下些什么吧!~~