最近接触到嵌入式系统,需要将驱动文件放到嵌入式设备内,所以想到搭建一个ftp服务器,通过ftp将文件放到设备内,通过搜索查找,使用stupid-ftpd比较合适,占用空间小,自己手边有个Android的机顶盒,就在机顶盒上实验
首先资源下载, stupid-ftpd是开源的,链接:https://sourceforge.net/projects/stupid-ftpd/files/stupid-ftpd/V1_5beta/
编译Android上可执行程序, 将stupid-ftpd目录名称修改为jni
jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#LOCAL_CFLAGS := -Wall -Wextra -Werror -Wunused
LOCAL_SRC_FILES := \
command.c \
ftpcommand.c \
ftpdconfig.c \
ls.c \
stupid-ftpd.c
LOCAL_MODULE := ftp
include $(BUILD_EXECUTABLE)
jni/Application.mk
APP_ABI := armeabi
stupid-ftpd编译出来的可执行程序,依赖conf配置文件,修改默认的stupid-ftpd.conf,内容如下,可以直接使用
#
# This is a config-file for stupid-ftpd
# ------------------------------------
#
# The standard path should be /etc/stupid-ftpd.conf
# You can define other paths by using the "-f" option
# when starting stupid-ftpd.
#
#
# ATTENTION: 1) Remember, that the server is running with YOUR permissions.
# It will fail to access other users directory, unless it is
# root, but it also allows to access ALL YOUR directories,
# which are deeper in a user's root-dir and YOU HAVE access to.
# 2) To solve the problem, the best way is to define a group-ID
# for stupid-ftpd.
# Or if you aren't root: set the MAIN root (serverroot=) to
# the highest directory depth which is possible.
# 3) REMEMBER: DO NOT PUT THIS FILE in an accessible directory!!!
# There are passwords defined here. The safest place is
# outside the serverroot.
# Server operation mode:
# daemon - quiet in background
# interactive - standard mode
#mode=interactive
mode=daemon
# chroot to
serverroot=/mnt
# type of chroot
# real - kernel chroot(), high security, but needs root privileges
# virtual - no real chroot(), software side (virtual) chroot
changeroottype=virtual
# Port number for the FTP-Protocol
port=21
# Maximum users allowed to log in
maxusers=10
# Message Of The Day (motd)
# It will be displayed after the login procedure.
#motd=/tmp/stupid-ftpd.motd
# Message on quit
# It will be displayed when quitting.
#byemsg=/tmp/stupid-ftpd.bye
# Log
#log=/tmp/stupid-ftpd.log
# User list:
# Format: user=<login> <passwd> <subdir> <maxlogins> <flags>
# <login> user name
# <passwd> password or * for anonymous access
# <subdir> (internally appended to serverroot)
# the user has access to the WHOLE SUBTREE,
# if the server has access to it
# <maxlogins> maximal logins with this usertype
# <flags> D - download
# U - upload + making directories
# O - overwrite existing files
# M - allows multiple logins
# E - allows erase operations
# A - allows EVERYTHING(!)
#
# user ftp is mapped to user anonymous, don't forget this
#
# Examples:
# user=user1 passx /tmp 2 D
# - login: user1, passwd: passx, max login twice (different IPs!)
# only download rights from directory /tmp
# user=user2 passy /home/user2 0 DU
# - login: user2, passwd: passy, no login count limit (different IPs!)
# download+upload rights to directory /home/user2
# user=user3 passz /home/user3 5 DUOM
# - login: user3, passwd: passz, max login count 5 (even from same IP)
# download+upload+overwrite rights to directory /home/user3
# user=user4 passq /tmp 10 -
# - login: user4, passwd: passq, max login count 10 (even from same IP)
# look-only rights at directory /tmp
#
# SEE: ATTENTION remark on the top of this file !!!
user=anonymous * / 5 A
# Banned hosts
# "*" and "?" are allowed here
#ban=192.168.*
#ban=localhost
#ban=*.banme.com
# Ban message (displayed to user who is banned)
# Please don't use more than 70 characters.
#banmsg=Go away !
# Login/password timeout
login-timeout=120
# Timeout (while logged in)
timeout=240
修改完成后,通过 ndk-build -B 编译可执行程序,将ftp 通过adb push 放置到机顶盒内,如果有root权限,放置到/system/bin下,没有权限就放到/data 下, 将conf 放到/etc下面,或者/data下。
启动ftp
ftp -f stupid-ftpd.conf
如果不报错,说明启动完成,可以通过 ps -A |grep ftp 查看,此时在windows系统通过ftp工具就可以访问了
ftp://192.168.1.113 usrname: anonymous port:21
Linux
在arm设备上,只要修改Makefile的gcc 为你嵌入式设备的编译链即可
例如:
CC=gcc ------------>>>> CC=arm-linux-gnueabihf-gcc
#EXEC=stupid-ftpd.Linux6
EXEC=ftp
执行make 编译生成 ftp可执行程序,将ftp 和conf文件放到tf卡内,在tf卡内运行服务,或者内置到镜像中去