From e82f3f21bff1cf021e036ce3e67d5cc12eb41ebe Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 4 Feb 2012 21:02:45 +0000 Subject: Add the beginnings of an FTP server git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4368 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/ftpd/ftpd_main.c | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 apps/examples/ftpd/ftpd_main.c (limited to 'apps/examples/ftpd/ftpd_main.c') diff --git a/apps/examples/ftpd/ftpd_main.c b/apps/examples/ftpd/ftpd_main.c new file mode 100755 index 000000000..b5f81f975 --- /dev/null +++ b/apps/examples/ftpd/ftpd_main.c @@ -0,0 +1,72 @@ +#include "ftpd.h" + +struct fptd_account_s +{ + uint8_t flags; + FAR const char *user; + FAR const char *password; + FAR const char *home; +} + +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)) + +static void ftpd_accounts(FTPD_SESSION handle) +{ + FAR onst struct fptd_account_s *account; + int i; + + for (i = 0; i < NACCOUNTS; i++) + { + account = &g_ftpdaccounts[i]; + ftpd_add_user(handle, account->flags, account->user, account->password, account->home); + } +} + +int ftpd_main(int s_argc, char **s_argv) +{ + FTPD_SESSION handle; + int ret; + + /* Bring up the network */ + + ret = ftpd_netinit(); + if (ret < 0) + { + ndbg("Failed to initialize the network\n"); + return EXIT_FAILURE; + } + + /* Open FTPD */ + + handle = ftpd_open(); + if (!handle) + { + ndbg("Failed to open FTPD\n"); + return EXIT_FAILURE; + } + + /* Configure acounts */ + + (void)ftpd_accounts(handle); + + /* Then drive the FTPD server */ + + while (g_ftpd_break == 0) + { + (void)ftpd_run(handle, 1000); + } + + /* Close the FTPD server and exit */ + + ftpd_close(handle); + return EXIT_SUCCESS; +} + +/* vim: set expandtab: */ +/* End of source */ -- cgit v1.2.3