mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-22 09:57:36 +08:00
Add the beginnings of an FTP server
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4368 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
Executable
+72
@@ -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 */
|
||||
Reference in New Issue
Block a user