嵌入式 linux-ftpd-0.17制作ftpd嵌入式linux下的ftp服务器

首先下载下嵌入式linux服务器资源,linux-ftpd-0.17.tar.gz 

下面我们将开始制作嵌入式linux下ftp服务器

1、解压资源

   tar xvzf linux-ftpd-0.17.tar.gz

2、修改configure文件

   vi configure,内容如下:

  

  1. #!/bin/sh  
  2. #  
  3. # This file was generated by confgen version 2.  
  4. # Do not edit.  
  5. #  
  6.   
  7. PREFIX='/usr'  
  8. #EXECPREFIX='$PREFIX'  
  9. INSTALLROOT=''  
  10. BINMODE='755'  
  11. #DAEMONMODE='$BINMODE'  
  12. MANMODE='644'  
  13.   
  14. while [ x$1 != x ]; do case $1 in  
  15.   
  16.     --help)  
  17.     cat <<EOF  
  18. Usage: configure [options]  
  19.     --help                Show this message  
  20.     --with-debug          Enable debugging  
  21.     --without-shadow      Disable shadow password support  
  22.     --prefix=path         Prefix for location of files [/usr]  
  23.     --exec-prefix=path    Location for arch-depedent files [prefix]  
  24.     --installroot=root    Top of filesystem tree to install in [/]  
  25.     --binmode=mode        Mode for binaries [755]  
  26.     --daemonmode=mode     Mode for daemon binaries [same as binmode]  
  27.     --manmode=mode        Mode for manual pages [644]  
  28.     --with-c-compiler=cc  Program for compiling C source [guessed]  
  29. EOF  
  30.     exit 0;;  
  31.     --verbose) ;;  
  32.     --quiet) ;;  
  33.   
  34.     --subdir) . ../configure.defs;;  
  35.   
  36.     --with-debug|--debug) DEBUG=1;;  
  37.     --prefix=*) PREFIX=`echo $1 | sed 's/^[^=]*=//'` ;;  
  38.     --exec-prefix=*) EXECPREFIX=`echo $1 | sed 's/^[^=]*=//'` ;;  
  39.     --installroot=*) INSTALLROOT=`echo $1 | sed 's/^[^=]*=//'` ;;  
  40.     --binmode=*) BINMODE=`echo $1 | sed 's/^[^=]*=//'` ;;  
  41.     --daemonmode=*) DAEMONMODE=`echo $1 | sed 's/^[^=]*=//'` ;;  
  42.     --manmode=*) MANMODE=`echo $1 | sed 's/^[^=]*=//'` ;;  
  43.     --with-c-compiler=*) CC=`echo $1 | sed 's/^[^=]*=//'` ;;  
  44.     --without-shadow|--disable-shadow) WITHOUT_SHADOW=1;;  
  45.     *) echo "Unrecognized option: $1"; exit 1;;  
  46. esac   
  47. shift  
  48. done  

上面我们能够清晰的看见configure的各个参数及作用,这里我不详细介绍各个参数的作用,这里我们如果想将ftpd服务器移植到嵌入式linux操作系统中,需要关注的主要是三个参数,分别是:prefix,installroot,with-c-compiler,其中prefix为installroot(文件系统根目录)目录下的具体目录,这里为什么需要将其与intallroot变量分开,主要是因为后续安装ftpd服务器时需要传递几个文件,所以需要根文件系统传递几个参数。

  prefix:这里的值我们不用修改,一般ftpd被安装到文件系统目录下的/usr/sbin中

  intallroot:文件系统的根目录,这里设置为/XXX/rootfs

  with-c-compiler:交叉编译器的选择,嵌入式linux肯定是arm-linux-gcc,(在传递交叉编译工具时,如果文件中这样添加WITH-C-COMPILER='arm-linux-gcc',好像会报错,所

  以我没直接在文件中传递这个参数,希望有大神能指点下为什么)

  这是我们运行./configure --with-c-compiler=arm-linux-gcc尝试配置下,结果出现如下信息:

    Directories: /usr/sbin /usr/man 
   Checking if C compiler works... no
   Compiler arm-linux-gcc does not exist or cannot compile C; try another.

  分析发现,我们传递的arm-linux-gcc出错,可是我的arm-linux-gcc编译内核都没问题,应该不会少文件,估计时configure文件内有错误,打开configure文件,找到错误信息

   比对发现:

   $CC __conftest.c -o __conftest || exit 1
          ./__conftest || exit 1

  ./__conftest肯定不能再linux下运行啊,所以果断将该文件中的./__conftest全部删除,总共8处。

  继续运行./configure --with-c-compiler=arm-linux-gcc,这次输出信息Ok:

 

  1. Directories: /usr/sbin /usr/man   
  2. Checking if C compiler works... yes  
  3. Checking if arm-linux-gcc accepts gcc warnings... yes  
  4. Checking if arm-linux-gcc accepts -O2... yes  
  5. Checking for yacc... bison -y  
  6. Checking for BSD signal semantics... yes  
  7. Checking for shadow... yes  
  8. Checking for crypt... -lcrypt  
  9. Checking for socklen_t... yes  
  10. Checking for snprintf declaration... ok  
  11. Checking for snprintf implementation... ok  
  12. Generating MCONFIG...  

3、接下来我们开始编译

   make,结果还是报错,

  

  1. ftpcmd.y:108: error: array type has incomplete element type  
  2. ftpcmd.y:109: error: array type has incomplete element type  
  3. ftpcmd.y: In function 'yylex':  
  4. ftpcmd.y:1055: warning: cast discards qualifiers from pointer target type  
  5. ftpcmd.y:1081: warning: cast discards qualifiers from pointer target type  
  6. make[1]: *** [ftpcmd.o] Error 1  
  7. make[1]: Leaving directory `/GT2440/linux-ftpd-0.17/ftpd'  

查看出错文件,vi ftpd/ftpcmd.y

 发现这块应该是tab结构体定义文件,将该文件中810行开始的结构体定义放到代码前面,ok。

  1. extern jmp_buf errcatch;  
  2.   
  3. #define    CMD    0    /* beginning of command */  
  4. #define    ARGS    1    /* expect miscellaneous arguments */  
  5. #define    STR1    2    /* expect SP followed by STRING */  
  6. #define    STR2    3    /* expect STRING */  
  7. #define    OSTR    4    /* optional SP then STRING */  
  8. #define    ZSTR1    5    /* SP then optional STRING */  
  9. #define    ZSTR2    6    /* optional STRING after SP */  
  10. #define    SITECMD    7    /* SITE command */  
  11. #define    NSTR    8    /* Number followed by a string */  
  12.   
  13.   
  14. //static void     help __P((struct tab *, char *));  
  15. static struct tab *  
  16.          lookup __P((struct tab *, char *));  
  17. static void     sizecmd __P((char *));  
  18. static int     yylex __P((void));  
  19. struct tab {  
  20.     const char  *name;  
  21.     short   token;  
  22.     short   state;  
  23.     short   implemented;    /* 1 if command is implemented */  
  24.     const char  *help;  
  25. };  
  26.   
  27. struct tab cmdtab[] = {     /* In order defined in RFC 765 */  
  28.     { "USER", USER, STR1, 1,    "<sp> username" },  
  29.     { "PASS", PASS, ZSTR1, 1,   "<sp> password" },  
  30.     { "ACCT", ACCT, STR1, 0,    "(specify account)" },  
  31.     { "SMNT", SMNT, ARGS, 0,    "(structure mount)" },  
  32.     { "REIN", REIN, ARGS, 0,    "(reinitialize server state)" },  
  33.     { "QUIT", QUIT, ARGS, 1,    "(terminate service)", },  
  34.     { "PORT", PORT, ARGS, 1,    "<sp> b0, b1, b2, b3, b4" },  
  35.     { "PASV", PASV, ARGS, 1,    "(set server in passive mode)" },  
  36.     { "TYPE", TYPE, ARGS, 1,    "<sp> [ A | E | I | L ]" },  
  37.     { "STRU", STRU, ARGS, 1,    "(specify file structure)" },  
  38.     { "MODE", MODE, ARGS, 1,    "(specify transfer mode)" },  
  39.     { "RETR", RETR, STR1, 1,    "<sp> file-name" },  
  40.     { "STOR", STOR, STR1, 1,    "<sp> file-name" },  
  41.     { "APPE", APPE, STR1, 1,    "<sp> file-name" },  
  42.     { "MLFL", MLFL, OSTR, 0,    "(mail file)" },  
  43.     { "MAIL", MAIL, OSTR, 0,    "(mail to user)" },  
  44.     { "MSND", MSND, OSTR, 0,    "(mail send to terminal)" },  
  45.     { "MSOM", MSOM, OSTR, 0,    "(mail send to terminal or mailbox)" },  
  46.     { "MSAM", MSAM, OSTR, 0,    "(mail send to terminal and mailbox)" },  
  47.     { "MRSQ", MRSQ, OSTR, 0,    "(mail recipient scheme question)" },  
  48.     { "MRCP", MRCP, STR1, 0,    "(mail recipient)" },  
  49.     { "ALLO", ALLO, ARGS, 1,    "allocate storage (vacuously)" },  
  50.     { "REST", REST, ARGS, 1,    "<sp> offset (restart command)" },  
  51.     { "RNFR", RNFR, STR1, 1,    "<sp> file-name" },  
  52.     { "RNTO", RNTO, STR1, 1,    "<sp> file-name" },  
  53.     { "ABOR", ABOR, ARGS, 1,    "(abort operation)" },  
  54.     { "DELE", DELE, STR1, 1,    "<sp> file-name" },  
  55.     { "CWD",  CWD,  OSTR, 1,    "[ <sp> directory-name ]" },  
  56.     { "XCWD", CWD,  OSTR, 1,    "[ <sp> directory-name ]" },  
  57.     { "LIST", LIST, OSTR, 1,    "[ <sp> path-name ]" },  
  58.     { "NLST", NLST, OSTR, 1,    "[ <sp> path-name ]" },  
  59.     { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" },  
  60.     { "SYST", SYST, ARGS, 1,    "(get type of operating system)" },  
  61.     { "STAT", STAT, OSTR, 1,    "[ <sp> path-name ]" },  
  62.     { "HELP", HELP, OSTR, 1,    "[ <sp> <string> ]" },  
  63.     { "NOOP", NOOP, ARGS, 1,    "" },  
  64.     { "MKD",  MKD,  STR1, 1,    "<sp> path-name" },  
  65.     { "XMKD", MKD,  STR1, 1,    "<sp> path-name" },  
  66.     { "RMD",  RMD,  STR1, 1,    "<sp> path-name" },  
  67.     { "XRMD", RMD,  STR1, 1,    "<sp> path-name" },  
  68.     { "PWD",  PWD,  ARGS, 1,    "(return current directory)" },  
  69.     { "XPWD", PWD,  ARGS, 1,    "(return current directory)" },  
  70.     { "CDUP", CDUP, ARGS, 1,    "(change to parent directory)" },  
  71.     { "XCUP", CDUP, ARGS, 1,    "(change to parent directory)" },  
  72.     { "STOU", STOU, STR1, 1,    "<sp> file-name" },  
  73.     { "SIZE", SIZE, OSTR, 1,    "<sp> path-name" },  
  74.     { "MDTM", MDTM, OSTR, 1,    "<sp> path-name" },  
  75.     { NULL,   0,    0,    0,    0 }  
  76. };  
  77.   
  78. struct tab sitetab[] = {  
  79.     { "UMASK", UMASK, ARGS, 1,  "[ <sp> umask ]" },  
  80.     { "IDLE", IDLE, ARGS, 1,    "[ <sp> maximum-idle-time ]" },  
  81.     { "CHMOD", CHMOD, NSTR, 1,  "<sp> mode <sp> file-name" },  
  82.     { "HELP", HELP, OSTR, 1,    "[ <sp> <string> ]" },  
  83.     { NULL,   0,    0,    0,    0 }  
  84. };  
重新编译,没有错误

4、安装ftpd,直接将ftpd拷贝到根文件系统目录下的/usr/sbin中,然后配置启动文件

在etc目录下的init.d/rcS文件中,添加如下内容:

  1. # These are standard services.  
  2. #  
  3. <span style="color:#FF0000;">ftp    stream  tcp nowait  root    /usr/sbin/ftpd      /usr/sbin/ftpd</span>  
  4. #telnet stream  tcp nowait  root    /usr/sbin/telnetd   /usr/sbin/telnetd -i  

修改/etc/passwd文件,添加如下内容:

  1. root::0:0:root:/:/bin/sh  
  2. ftp::14:50:FTP User:/var/ftp:  
  3. bin:*:1:1:bin:/bin:  
  4. daemon:*:2:2:daemon:/sbin:  
  5. nobody:*:99:99:Nobody:/:  
  6. plg:$1$wwtsqwnk$sWaEJGcJFTqaCW18sbUK7/:502:502:Linux User,,,:/home/plg:/bin/sh  

但是,发现启动ftp服务后,需要挺长时间才能登陆上。因此推荐大家还是使用vsftpd-2.3.4,感觉比ftpd好用。

VSftpd-2.3.4使用:http://blog.csdn.net/alan00000/article/details/7194702

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值