ftp客户端移植(基于netkit-ftp-0.17.tar.gz)

2019-07-13 01:35发布

使用busybox制作的根文件系统,没有ftp客户端工具,无法登录到其他的ftp服务器,需要自己编译ftp指令。 在这里采用源码包netkit-ftp-0.17.tar.gz编译,步骤如下: 1、tar解压 2、打补丁 patch -p1< netkit-ftp-0.17-cross.patch
在源码目录下,建立上述名字的补丁文件,内容如下:
diff -Naur netkit-ftp-0.17.orig/configure netkit-ftp-0.17/configure
--- netkit-ftp-0.17.orig/configure 2008-01-21 15:27:56.000000000 -0500
+++ netkit-ftp-0.17/configure 2008-01-21 15:27:58.000000000 -0500
@@ -93,7 +93,6 @@
echo 'no'
echo 'Compiler '"$CC"' does not exist or cannot compile C; try another.'
rm -f __conftest*
- exit
fi
fi

@@ -180,7 +179,6 @@
echo 'no'
echo 'This package needs BSD signal semantics to run.'
rm -f __conftest*
- exit
fi
fi
rm -f __conftest*
@@ -238,7 +236,6 @@
echo 'not found'
echo 'This package needs termcap to run.'
rm -f __conftest*
- exit
fi
fi
rm -f __conftest*
@@ -323,7 +320,6 @@
echo 'no'
echo 'Cannot work out what to use for socklen_t. Help...'
rm -f __conftest*
- exit
fi
fi
fi
@@ -400,7 +396,6 @@
echo 'missing'
echo 'This package requires snprintf.'
rm -f __conftest*
- exit
fi
fi
fi
diff -Naur netkit-ftp-0.17.orig/ftp/cmds.c netkit-ftp-0.17/ftp/cmds.c
--- netkit-ftp-0.17.orig/ftp/cmds.c 2008-01-21 15:27:56.000000000 -0500
+++ netkit-ftp-0.17/ftp/cmds.c 2008-01-21 15:27:58.000000000 -0500
@@ -68,6 +68,10 @@
#include "cmds.h"
#include "glob.h"

+#ifndef index
+#define index strchr
+#endif
+
void intr(int);

extern FILE *cout;
diff -Naur netkit-ftp-0.17.orig/ftp/ftp.c netkit-ftp-0.17/ftp/ftp.c
--- netkit-ftp-0.17.orig/ftp/ftp.c 2008-01-21 15:27:56.000000000 -0500
+++ netkit-ftp-0.17/ftp/ftp.c 2008-01-21 15:27:58.000000000 -0500
@@ -65,6 +65,13 @@

#include "../version.h"

+#ifndef index
+#define index strchr
+#endif
+#ifndef rindex
+#define rindex strrchr
+#endif
+
int data = -1;
off_t restart_point = 0;

diff -Naur netkit-ftp-0.17.orig/ftp/Makefile netkit-ftp-0.17/ftp/Makefile
--- netkit-ftp-0.17.orig/ftp/Makefile 2008-01-21 15:27:56.000000000 -0500
+++ netkit-ftp-0.17/ftp/Makefile 2008-01-21 15:30:01.000000000 -0500
@@ -16,11 +16,12 @@
cmds.o glob.o: glob.h

install: ftp
- install -s -m$(BINMODE) ftp $(INSTALLROOT)$(BINDIR)
- ln -sf ftp $(INSTALLROOT)$(BINDIR)/pftp
- install -m$(MANMODE) ftp.1 $(INSTALLROOT)$(MANDIR)/man1
- ln -sf ftp.1 $(INSTALLROOT)$(MANDIR)/man1/pftp.1
- install -m$(MANMODE) netrc.5 $(INSTALLROOT)$(MANDIR)/man5
+ mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man{1,5}
+ install -m$(BINMODE) ftp $(DESTDIR)$(BINDIR)
+ cd $(DESTDIR)$(BINDIR)/ && ln -sf ftp pftp
+ install -m$(MANMODE) ftp.1 $(DESTDIR)$(MANDIR)/man1
+ cd $(DESTDIR)$(MANDIR)/man1 && ln -sf ftp.1 pftp.1
+ install -m$(MANMODE) netrc.5 $(DESTDIR)$(MANDIR)/man5

clean:
rm -f *.o ftp
diff -Naur netkit-ftp-0.17.orig/ftp/ruserpass.c netkit-ftp-0.17/ftp/ruserpass.c
--- netkit-ftp-0.17.orig/ftp/ruserpass.c 2008-01-21 15:27:56.000000000 -0500
+++ netkit-ftp-0.17/ftp/ruserpass.c 2008-01-21 15:27:58.000000000 -0500
@@ -58,6 +58,10 @@
#define ID 10
#define MACH 11

+#ifndef index
+#define index strchr
+#endif
+
static char tokval[100];

static struct toktab {

3、指定交叉编译工具,进行configure ./configure --with-c-compiler=arm-none-linux-gnueabi-gcc 

4、make make时可能出现以下错误: glob.c: In function 'ftpglob':
glob.c:126:15: error: 'ARG_MAX' undeclared (first use in this function)
glob.c:126:15: note: each undeclared identifier is reported only once for each function it appears in
glob.c: In function 'ginit':
glob.c:167:11: error: 'ARG_MAX' undeclared (first use in this function)
glob.c: In function 'Gcat':
glob.c:582:32: error: 'ARG_MAX' undeclared (first use in this function)
make[1]: *** [glob.o] 错误 1
make[1]:正在离开目录 `/home/am335x/package/netkit-ftp-0.17/ftp'
make: *** [ftp.build] 错误 2
从网上查找解决方法如下: 修改glob.c,#include “glob.h”添加: #if define (_POSIX_ARG_MAX)        #if define (ARG_MAX)      #undef ARG_MAX #endif #endif 但是经过实验,问题依然没有解决。 。。。。(待寻找正确、合理的方法解决)。。。。。
5、将编译的ftp指令上传到根文件系统,测试一下看看: ftp: error while loading shared libraries: libreadline.so.5: cannot open shared object file: No such file or directory
ftp: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
ftp: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
分别在交叉编译工具的库中找到上述3个库,拷贝到根文件系统的lib目录下。 接下来可以正常的从ftp服务器get想要的文件了。