Added FTP server sample application
authorJeonginKim <ji1.kim@samsung.com>
Tue, 1 Aug 2017 04:42:07 +0000 (13:42 +0900)
committerJeonginKim <ji1.kim@samsung.com>
Tue, 1 Aug 2017 10:18:54 +0000 (19:18 +0900)
apps/examples/ftpd/Kconfig [new file with mode: 0644]
apps/examples/ftpd/Kconfig_ENTRY [new file with mode: 0644]
apps/examples/ftpd/Make.defs [new file with mode: 0644]
apps/examples/ftpd/Makefile [new file with mode: 0644]
apps/examples/ftpd/ftpd.h [new file with mode: 0644]
apps/examples/ftpd/ftpd_main.c [new file with mode: 0644]

diff --git a/apps/examples/ftpd/Kconfig b/apps/examples/ftpd/Kconfig
new file mode 100644 (file)
index 0000000..a62dcdc
--- /dev/null
@@ -0,0 +1,15 @@
+#
+# For a description of the syntax of this configuration file,
+# see kconfig-language at https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt
+#
+
+config EXAMPLES_FTPD
+       bool "FTP server example"
+       depends on NETUTILS_FTPD
+       default n
+       ---help---
+               Enable the FTP server example
+
+config USER_ENTRYPOINT
+       string
+       default "ftpd_main" if ENTRY_FTPD
diff --git a/apps/examples/ftpd/Kconfig_ENTRY b/apps/examples/ftpd/Kconfig_ENTRY
new file mode 100644 (file)
index 0000000..82fd30c
--- /dev/null
@@ -0,0 +1,3 @@
+config ENTRY_FTPD
+       bool "FTP Server example"
+       depends on EXAMPLES_FTPD
diff --git a/apps/examples/ftpd/Make.defs b/apps/examples/ftpd/Make.defs
new file mode 100644 (file)
index 0000000..6ed934e
--- /dev/null
@@ -0,0 +1,56 @@
+###########################################################################
+#
+# Copyright 2017 Samsung Electronics All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+# either express or implied. See the License for the specific
+# language governing permissions and limitations under the License.
+#
+###########################################################################
+############################################################################
+# apps/examples/ftpd/Make.defs
+# Adds selected applications to apps/ build
+#
+#   Copyright (C) 2015 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+#    used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+ifeq ($(CONFIG_EXAMPLES_FTPD),y)
+CONFIGURED_APPS += examples/ftpd
+endif
diff --git a/apps/examples/ftpd/Makefile b/apps/examples/ftpd/Makefile
new file mode 100644 (file)
index 0000000..d7563c8
--- /dev/null
@@ -0,0 +1,159 @@
+###########################################################################
+#
+# Copyright 2017 Samsung Electronics All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+# either express or implied. See the License for the specific
+# language governing permissions and limitations under the License.
+#
+###########################################################################
+############################################################################
+# apps/examples/ftpd/Makefile
+#
+#   Copyright (C) 2008, 2010-2013 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+#    used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+-include $(TOPDIR)/.config
+-include $(TOPDIR)/Make.defs
+include $(APPDIR)/Make.defs
+
+# built-in application info
+
+APPNAME = ftpd
+THREADEXEC = TASH_EXECMD_ASYNC
+FUNCNAME = ftpd_main
+
+# ftp server example
+
+ASRCS =
+CSRCS = 
+MAINSRC = ftpd_main.c
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
+OBJS = $(AOBJS) $(COBJS)
+
+ifneq ($(CONFIG_BUILD_KERNEL),y)
+  OBJS += $(MAINOBJ)
+endif
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+  BIN = ..\..\libapps$(LIBEXT)
+else
+ifeq ($(WINTOOL),y)
+  BIN = ..\\..\\libapps$(LIBEXT)
+else
+  BIN = ../../libapps$(LIBEXT)
+endif
+endif
+
+ifeq ($(WINTOOL),y)
+  INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
+else
+  INSTALL_DIR = $(BIN_DIR)
+endif
+
+CONFIG_EXAMPLES_FTPD_PROGNAME ?= ftpd$(EXEEXT)
+PROGNAME = $(CONFIG_EXAMPLES_FTPD_PROGNAME)
+
+ROOTDEPPATH = --dep-path .
+
+
+# Common build
+
+VPATH =
+
+all: .built
+.PHONY: clean depend distclean
+
+$(AOBJS): %$(OBJEXT): %.S
+       $(call ASSEMBLE, $<, $@)
+
+$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
+       $(call COMPILE, $<, $@)
+
+.built: $(OBJS)
+       $(call ARCHIVE, $(BIN), $(OBJS))
+       @touch .built
+
+ifeq ($(CONFIG_BUILD_KERNEL),y)
+$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ)
+       @echo "LD: $(PROGNAME)"
+       $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS)
+       $(Q) $(NM) -u  $(INSTALL_DIR)$(DELIM)$(PROGNAME)
+
+install: $(BIN_DIR)$(DELIM)$(PROGNAME)
+
+else
+install:
+
+endif
+
+ifeq ($(CONFIG_BUILTIN_APPS)$(CONFIG_EXAMPLES_FTPD),yy)
+$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
+       $(call REGISTER,$(APPNAME),$(FUNCNAME),$(THREADEXEC))
+
+context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
+
+else
+context:
+
+endif
+
+.depend: Makefile $(SRCS)
+       @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+       @touch $@
+
+depend: .depend
+
+clean:
+       $(call DELFILE, .built)
+       $(call CLEAN)
+
+distclean: clean
+       $(call DELFILE, Make.dep)
+       $(call DELFILE, .depend)
+
+-include Make.dep
+.PHONY: preconfig
+preconfig:
diff --git a/apps/examples/ftpd/ftpd.h b/apps/examples/ftpd/ftpd.h
new file mode 100644 (file)
index 0000000..cd7f12b
--- /dev/null
@@ -0,0 +1,136 @@
+/****************************************************************************
+ *
+ * Copyright 2017 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * apps/examples/ftpd/ftpd.h
+ * Interface for the Contiki ftpd.
+ *
+ *   Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ *    products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __APPS_EXAMPLES_FTPD_FTPD_H
+#define __APPS_EXAMPLES_FTPD_FTPD_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#include <tinyara/config.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+/* Configuration ************************************************************/
+/* CONFIG_EXAMPLES_FTPD_PRIO - Priority of the FTP daemon.
+ *   Default: SCHED_PRIORITY_DEFAULT
+ * CONFIG_EXAMPLES_FTPD_STACKSIZE - Stack size allocated for the
+ *   FTP daemon. Default: 2048
+ * CONFIG_EXAMPLES_FTPD_NONETINIT - Define to suppress configuration of the
+ *   network by apps/examples/ftpd.  You would need to suppress network
+ *   configuration if the network is configuration prior to running the
+ *   example.
+ *
+ * If CONFIG_EXAMPLES_FTPD_NONETINIT is not defined, then the following may
+ * be specified to customized the network configuration:
+ *
+ * CONFIG_EXAMPLES_FTPD_NOMAC - If the hardware has no MAC address of its
+ *   own, define this =y to provide a bogus address for testing.
+ * CONFIG_EXAMPLES_FTPD_IPADDR - The target IP address.  Default 10.0.0.2
+ * CONFIG_EXAMPLES_FTPD_DRIPADDR - The default router address. Default
+ *   10.0.0.1
+ * CONFIG_EXAMPLES_FTPD_NETMASK - The network mask.  Default: 255.255.255.0
+ */
+
+#define CONFIG_EXAMPLES_FTPD_PRIO SCHED_PRIORITY_DEFAULT
+#define CONFIG_EXAMPLES_FTPD_STACKSIZE 2048
+
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* This structure describes one entry in a table of accounts */
+
+struct fptd_account_s {
+       uint8_t         flags;
+       FAR const char *user;
+       FAR const char *password;
+       FAR const char *home;
+};
+
+/* To minimize the probability of name collisitions, all FTPD example
+ * global data is maintained in single structure.
+ */
+
+struct ftpd_globals_s {
+       bool          initialized; /* True: Networking is initialized.  The
+                              * network must be initialized only once.
+                              */
+       volatile bool stop;        /* True: Request daemon to exit */
+       volatile bool running;     /* True: The daemon is running */
+       pid_t         pid;         /* Task ID of the FTPD daemon.  The value
+                              * -1 is a redundant indication that the
+                              * daemon is not running.
+                              */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* To minimize the probability of name collisitions, all FTPD example
+ * global data is maintained in a single instance of a structure.
+ */
+
+extern struct ftpd_globals_s g_ftpdglob;
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#endif /* __APPS_EXAMPLES_FTPD_FTPD_H */
diff --git a/apps/examples/ftpd/ftpd_main.c b/apps/examples/ftpd/ftpd_main.c
new file mode 100644 (file)
index 0000000..6e662db
--- /dev/null
@@ -0,0 +1,238 @@
+/****************************************************************************
+ *
+ * Copyright 2017 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * examples/ftpd/ftpd_main.c
+ *
+ *   Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sched.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <apps/netutils/netlib.h>
+#include <apps/netutils/ftpd.h>
+
+#include "ftpd.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct fptd_account_s g_ftpdaccounts[] = {
+       { FTPD_ACCOUNTFLAG_SYSTEM, "root",      "abc123", NULL },
+       { FTPD_ACCOUNTFLAG_GUEST,  "ftp",       NULL,     NULL },
+       { FTPD_ACCOUNTFLAG_GUEST,  "anonymous", NULL,     NULL },
+};
+#define NACCOUNTS (sizeof(g_ftpdaccounts) / sizeof(struct fptd_account_s))
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* To minimize the probability of name collisitions, all FTPD example
+ * global data is maintained in a single instance of a structure.
+ */
+
+struct ftpd_globals_s g_ftpdglob;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+/****************************************************************************
+ * Name: ftpd_accounts
+ ****************************************************************************/
+
+static void ftpd_accounts(FTPD_SESSION handle)
+{
+       FAR const struct fptd_account_s *account;
+       int i;
+
+       printf("Adding accounts:\n");
+       for (i = 0; i < NACCOUNTS; i++) {
+               account = &g_ftpdaccounts[i];
+
+               printf("%d. %s account: USER=%s PASSWORD=%s HOME=%s\n", i + 1,
+                          (account->flags & FTPD_ACCOUNTFLAG_SYSTEM) != 0 ? "Root" : "User",
+                          (!account->user) ? "(none)" : account->user,
+                          (!account->password) ? "(none)" : account->password,
+                          (!account->home) ? "(none)" : account->home);
+
+               ftpd_adduser(handle, account->flags, account->user,
+                                        account->password, account->home);
+       }
+}
+
+/****************************************************************************
+ * Name: ftpd_daemon
+ ****************************************************************************/
+
+int ftpd_daemon(int s_argc, char **s_argv)
+{
+       FTPD_SESSION handle;
+       int ret;
+
+       /* The FTPD daemon has been started */
+
+       g_ftpdglob.running = true;
+
+       printf("FTP daemon [%d] started\n", g_ftpdglob.pid);
+
+       /* Open FTPD */
+
+       handle = ftpd_open();
+       if (!handle) {
+               printf("FTP daemon [%d] failed to open FTPD\n", g_ftpdglob.pid);
+               g_ftpdglob.running = false;
+               g_ftpdglob.stop    = false;
+               g_ftpdglob.pid     = -1;
+               return EXIT_FAILURE;
+       }
+
+       /* Configure acounts */
+
+       (void)ftpd_accounts(handle);
+
+       /* Then drive the FTPD server. */
+
+
+       while (g_ftpdglob.stop == 0) {
+               /* If ftpd_session returns success, it means that a new FTP session
+                * has been started.
+                */
+
+               ret = ftpd_session(handle, 5000);
+
+               /* If any interesting happened (i.e., any thing other than a timeout),
+                * then report the interesting event.
+                */
+
+               if (ret != -ETIMEDOUT) {
+                       printf("FTP daemon [%d] ftpd_session returned %d\n", g_ftpdglob.pid, ret);
+               }
+       }
+
+       /* Close the FTPD server and exit (we can get here only if
+        * CONFIG_NSH_BUILTIN_APPS is defined).
+        */
+
+       printf("FTP daemon [%d] stopping\n", g_ftpdglob.pid);
+       g_ftpdglob.running = false;
+       g_ftpdglob.stop    = false;
+       g_ftpdglob.pid     = -1;
+       ftpd_close(handle);
+       return EXIT_SUCCESS;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+/****************************************************************************
+ * Name: ftpd_main
+ ****************************************************************************/
+int ftpd_main(int s_argc, char **s_argv)
+{
+       /* Check if we have already initialized the network */
+
+       if (!g_ftpdglob.initialized) {
+
+               /* Bring up the network */
+
+               printf("Initializing the network\n");
+
+               /* Initialize daemon state */
+
+               g_ftpdglob.initialized = true;
+               g_ftpdglob.pid         = -1;
+               g_ftpdglob.stop        = false;
+               g_ftpdglob.running     = false;
+       }
+
+       /* Then start the new daemon (if it is not already running) */
+
+       if (g_ftpdglob.stop && g_ftpdglob.running) {
+               printf("Waiting for FTP daemon [%d] to stop\n", g_ftpdglob.pid);
+               return EXIT_FAILURE;
+       } else if (!g_ftpdglob.running) {
+               printf("Starting the FTP daemon\n");
+               g_ftpdglob.pid = task_create("FTP daemon", CONFIG_EXAMPLES_FTPD_PRIO,
+                                                                        CONFIG_EXAMPLES_FTPD_STACKSIZE,
+                                                                        ftpd_daemon, NULL);
+               if (g_ftpdglob.pid < 0) {
+                       printf("Failed to start the FTP daemon: %d\n", errno);
+                       return EXIT_FAILURE;
+               }
+       } else {
+               printf("FTP daemon [%d] is running\n", g_ftpdglob.pid);
+       }
+
+       return EXIT_SUCCESS;
+}
+
+/****************************************************************************
+ * Name: ftpd_stop
+ ****************************************************************************/
+int ftpd_stop(int s_argc, char **s_argv)
+{
+       if (!g_ftpdglob.initialized || !g_ftpdglob.running) {
+               printf("The FTP daemon not running\n");
+               return EXIT_FAILURE;
+       }
+
+       printf("Stopping the FTP daemon, pid=%d\n", g_ftpdglob.pid);
+       g_ftpdglob.stop = true;
+       return EXIT_SUCCESS;
+}