加入星計(jì)劃,您可以享受以下權(quán)益:

  • 創(chuàng)作內(nèi)容快速變現(xiàn)
  • 行業(yè)影響力擴(kuò)散
  • 作品版權(quán)保護(hù)
  • 300W+ 專業(yè)用戶
  • 1.5W+ 優(yōu)質(zhì)創(chuàng)作者
  • 5000+ 長(zhǎng)期合作伙伴
立即加入
  • 正文
  • 相關(guān)推薦
  • 電子產(chǎn)業(yè)圖譜
申請(qǐng)入駐 產(chǎn)業(yè)圖譜

如何移植ftp服務(wù)器到arm板子?

11/21 08:45
628
閱讀需 47 分鐘
加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點(diǎn)資訊討論

很多廠家提供的sdk,一般都不自帶ftp服務(wù)器功能,需要要發(fā)人員自己移植ftp服務(wù)器程序。

本文手把手教大家如何移植ftp server到arm板子。

環(huán)境

sdk:復(fù)旦微
Buildroot?2018.02.3

1. ?解壓

$?mkdir?~/vsftpd?
$?cp?vsftpd-3.0.2.tar.gz?~/vsftpd?
$?cd?~/vsftpd?$?tar?xzf?vsftpd-3.0.2.tar.gz?
$?cd?vsftpd-3.0.2/

軟件包獲取方法:件文末。

2. ?配置工具鏈

修改Makefile文件:

CC?=?arm-linux-gnueabihf-gcc

根據(jù)自己的平臺(tái)的工具鏈

3. 設(shè)置交叉編譯環(huán)境&編譯

peng@ubuntu:~/vsftpd/vsftpd-3.0.2$?make
arm-linux-gnueabihf-gcc?-c?main.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?utility.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?prelogin.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?ftpcmdio.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?postlogin.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?privsock.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?tunables.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?ftpdataio.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?secbuf.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?ls.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?postprivparent.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?logging.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?str.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?netstr.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?sysstr.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?strlist.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?banner.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?filestr.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?parseconf.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?secutil.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?ascii.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?oneprocess.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?twoprocess.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?privops.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?standalone.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?hash.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?tcpwrap.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?ipaddrparse.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?access.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?features.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?readwrite.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?opts.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?ssl.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?sslslave.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?ptracesandbox.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?ftppolicy.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?sysutil.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?sysdeputil.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-c?seccompsandbox.c?-O2?-fPIE?-fstack-protector?--param=ssp-buffer-size=4?-Wall?-W?-Wshadow?-Werror?-Wformat-security?-D_FORTIFY_SOURCE=2??-idirafter?dummyinc
arm-linux-gnueabihf-gcc?-o?vsftpd?main.o?utility.o?prelogin.o?ftpcmdio.o?postlogin.o?privsock.o?tunables.o?ftpdataio.o?secbuf.o?ls.o?postprivparent.o?logging.o?str.o?netstr.o?sysstr.o?strlist.o?banner.o?filestr.o?parseconf.o?secutil.o?ascii.o?oneprocess.o?twoprocess.o?privops.o?standalone.o?hash.o?tcpwrap.o?ipaddrparse.o?access.o?features.o?readwrite.o?opts.o?ssl.o?sslslave.o?ptracesandbox.o?ftppolicy.o?sysutil.o?sysdeputil.o?seccompsandbox.o?-Wl,-s?-fPIE?-pie?-Wl,-z,relro?-Wl,-z,now?`./vsf_findlibs.sh`

make 后,當(dāng)前目錄下會(huì)生成兩個(gè)文件:vsftpdvsftpd.conf,這兩個(gè)文件是我們要用的。

4. 復(fù)制文件

將生成的 vsftpd 復(fù)制到目標(biāo)板 /usr/sbin 目錄,vsftpd.conf 復(fù)制到目標(biāo)板 /etc 目錄,并添加 vsftpd 為可執(zhí)行:

    復(fù)制執(zhí)行文件到目標(biāo)板
vsftpd拷貝到板子usr/sbin
    添加可執(zhí)行權(quán)限
chmod?+x?/usr/sbin/vsftpd?
    復(fù)制配置文件到目標(biāo)板
?vsftpd.conf?拷貝到板子/etc/?

5. 配置

在目標(biāo)板上創(chuàng)建一個(gè)本地用戶ftp,并設(shè)置密碼123456

$?adduser?ftp?
Changing?password?for?root?
New?password:??
Retype?password:??
Password?for?ftpadmin?changed?by?root

使用 vi 打開 vsftpd.conf 文件,并進(jìn)行配置,如下配置可實(shí)現(xiàn)正常上傳下載功能,(這段可以隨便改)

用戶:ftp

#?Example?config?file?/etc/vsftpd.conf
#
#?The?default?compiled?in?settings?are?fairly?paranoid.?This?sample?file
#?loosens?things?up?a?bit,?to?make?the?ftp?daemon?more?usable.
#?Please?see?vsftpd.conf.5?for?all?compiled?in?defaults.
#
#?READ?THIS:?This?example?file?is?NOT?an?exhaustive?list?of?vsftpd?options.
#?Please?read?the?vsftpd.conf.5?manual?page?to?get?a?full?idea?of?vsftpd's
#?capabilities.
#
#?Allow?anonymous?FTP??(Beware?-?allowed?by?default?if?you?comment?this?out).
anonymous_enable=YES
#
#?Uncomment?this?to?allow?local?users?to?log?in.
local_enable=YES
#
#?Uncomment?this?to?enable?any?form?of?FTP?write?command.
write_enable=YES
#
#?Default?umask?for?local?users?is?077.?You?may?wish?to?change?this?to?022,
#?if?your?users?expect?that?(022?is?used?by?most?other?ftpd's)
local_umask=022
file_open_mode=0777
#
#?Uncomment?this?to?allow?the?anonymous?FTP?user?to?upload?files.?This?only
#?has?an?effect?if?the?above?global?write?enable?is?activated.?Also,?you?will
#?obviously?need?to?create?a?directory?writable?by?the?FTP?user.
anon_upload_enable=YES
#
#?Uncomment?this?if?you?want?the?anonymous?FTP?user?to?be?able?to?create
#?new?directories.
anon_mkdir_write_enable=YES
#
#?Activate?directory?messages?-?messages?given?to?remote?users?when?they
#?go?into?a?certain?directory.
dirmessage_enable=YES
#
#?Activate?logging?of?uploads/downloads.
xferlog_enable=YES
#
#?Make?sure?PORT?transfer?connections?originate?from?port?20?(ftp-data).
connect_from_port_20=YES
#
#?If?you?want,?you?can?arrange?for?uploaded?anonymous?files?to?be?owned?by
#?a?different?user.?Note!?Using?"root"?for?uploaded?files?is?not
#?recommended!
#chown_uploads=YES
#chown_username=whoever
#
#?You?may?override?where?the?log?file?goes?if?you?like.?The?default?is?shown
#?below.
xferlog_file=/var/log/vsftpd.log
#
#?If?you?want,?you?can?have?your?log?file?in?standard?ftpd?xferlog?format.
#?Note?that?the?default?log?file?location?is?/var/log/xferlog?in?this?case.
#xferlog_std_format=YES
#
#?You?may?change?the?default?value?for?timing?out?an?idle?session.
#idle_session_timeout=600
#
#?You?may?change?the?default?value?for?timing?out?a?data?connection.
#data_connection_timeout=120
#
#?It?is?recommended?that?you?define?on?your?system?a?unique?user?which?the
#?ftp?server?can?use?as?a?totally?isolated?and?unprivileged?user.
#nopriv_user=ftpsecure
#
#?Enable?this?and?the?server?will?recognise?asynchronous?ABOR?requests.?Not
#?recommended?for?security?(the?code?is?non-trivial).?Not?enabling?it,
#?however,?may?confuse?older?FTP?clients.
#async_abor_enable=YES
#
#?By?default?the?server?will?pretend?to?allow?ASCII?mode?but?in?fact?ignore
#?the?request.?Turn?on?the?below?options?to?have?the?server?actually?do?ASCII
#?mangling?on?files?when?in?ASCII?mode.
#?Beware?that?on?some?FTP?servers,?ASCII?support?allows?a?denial?of?service
#?attack?(DoS)?via?the?command?"SIZE?/big/file"?in?ASCII?mode.?vsftpd
#?predicted?this?attack?and?has?always?been?safe,?reporting?the?size?of?the
#?raw?file.
#?ASCII?mangling?is?a?horrible?feature?of?the?protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
#?You?may?fully?customise?the?login?banner?string:
ftpd_banner=Welcome?to?6902?FTP?service.
#
#?You?may?specify?a?file?of?disallowed?anonymous?e-mail?addresses.?Apparently
#?useful?for?combatting?certain?DoS?attacks.
#deny_email_enable=YES
#?(default?follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
#?You?may?specify?an?explicit?list?of?local?users?to?chroot()?to?their?home
#?directory.?If?chroot_local_user?is?YES,?then?this?list?becomes?a?list?of
#?users?to?NOT?chroot().
#?(Warning!?chroot'ing?can?be?very?dangerous.?If?using?chroot,?make?sure?that
#?the?user?does?not?have?write?access?to?the?top?level?directory?within?the
#?chroot)
#chroot_local_user=YES
#chroot_list_enable=YES
#?(default?follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
#?You?may?activate?the?"-R"?option?to?the?builtin?ls.?This?is?disabled?by
#?default?to?avoid?remote?users?being?able?to?cause?excessive?I/O?on?large
#?sites.?However,?some?broken?FTP?clients?such?as?"ncftp"?and?"mirror"?assume
#?the?presence?of?the?"-R"?option,?so?there?is?a?strong?case?for?enabling?it.
#ls_recurse_enable=YES
#
#?When?"listen"?directive?is?enabled,?vsftpd?runs?in?standalone?mode?and
#?listens?on?IPv4?sockets.?This?directive?cannot?be?used?in?conjunction
#?with?the?listen_ipv6?directive.
listen=YES
#
#?This?directive?enables?listening?on?IPv6?sockets.?To?listen?on?IPv4?and?IPv6
#?sockets,?you?must?run?two?copies?of?vsftpd?with?two?configuration?files.
#?Make?sure,?that?one?of?the?listen?options?is?commented?!!
#listen_ipv6=YES

ftp_username=ftp????????????#登錄用戶
secure_chroot_dir=/mnt/?????#

6. 打開vsftp

配置完之后,在目標(biāo)板上打開vsftp,命令:

#?/usr/sbin/vsftpd?&

注意,后面還有一個(gè) &,表示該服務(wù)放到后臺(tái)運(yùn)行。

7. 設(shè)置開機(jī)自啟動(dòng)

如果要讓 vsftpd 開機(jī)啟動(dòng),可以創(chuàng)建下面文件S70vsftpd,

然后將該文件添加到/etc/init.d/目錄下。

#!?/bin/sh

set?-e

DESC="vsftpd"
NAME=vsftpd
DAEMON=/usr/sbin/$NAME

case?"$1"?in
??start)
?printf?"Starting?$DESC:?"
?start-stop-daemon?-S?-b?-x?$NAME
?echo?"OK"
?;;
??stop)
?printf?"Stopping?$DESC:?"
?start-stop-daemon?-K?-x?$NAME
?echo?"OK"
?;;
??restart|force-reload)
?echo?"Restarting?$DESC:?"
?$0?stop
?sleep?1
?$0?start
?echo?""
?;;
??*)
?echo?"Usage:?$0?{start|stop|restart|force-reload}"?>&2
?exit?1
?;;
esac

exit?0

開啟vsftpd:

?/etc/init.d/S70vsftpd?restart

重啟vsftpd:

?/etc/init.d/S70vsftpd?restart

8. ?客戶端測(cè)試

下面以pc為例:

C:Usersricks>ftp
ftp>?open?192.168.31.45
連接到 192.168.31.45。
220?Welcome?to?EC20?FTP?service.
200?Always?in?UTF8?mode.
用戶(192.168.31.45:(none)):?root
331?Please?specify?the?password.
密碼:
230?Login?successful.
    顯示文件列表
ftp>?ls
200?PORT?command?successful.?Consider?using?PASV.
150?Here?comes?the?directory?listing.
123
226?Directory?send?OK.
ftp:?收到 5 字節(jié),用時(shí)?0.00秒 1.25千字節(jié)/秒。
    下載文件
ftp>?get?123
200?PORT?command?successful.?Consider?using?PASV.
150?Opening?BINARY?mode?data?connection?for?123?(8?bytes).
226?Transfer?complete.
ftp:?收到 8 字節(jié),用時(shí)?0.00秒 8.00千字節(jié)/秒。
    退出
ftp>?quit
221?Goodbye.

后臺(tái)回復(fù):tools

相關(guān)推薦

電子產(chǎn)業(yè)圖譜

公眾號(hào)『一口Linux』號(hào)主彭老師,擁有15年嵌入式開發(fā)經(jīng)驗(yàn)和培訓(xùn)經(jīng)驗(yàn)。曾任職ZTE,某研究所,華清遠(yuǎn)見教學(xué)總監(jiān)。擁有多篇網(wǎng)絡(luò)協(xié)議相關(guān)專利和軟件著作。精通計(jì)算機(jī)網(wǎng)絡(luò)、Linux系統(tǒng)編程、ARM、Linux驅(qū)動(dòng)、龍芯、物聯(lián)網(wǎng)。原創(chuàng)內(nèi)容基本從實(shí)際項(xiàng)目出發(fā),保持原理+實(shí)踐風(fēng)格,適合Linux驅(qū)動(dòng)新手入門和技術(shù)進(jìn)階。