From 55a36b724c7cfe2ec3a4700a8588dc4ff44cb439 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 21 Nov 2012 10:59:18 +0100 Subject: ftpd: Add SIZE command --- cpukit/ftpd/ftpd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cpukit/ftpd/ftpd.c b/cpukit/ftpd/ftpd.c index 905f40c2d8..8ffd878d2d 100644 --- a/cpukit/ftpd/ftpd.c +++ b/cpukit/ftpd/ftpd.c @@ -198,6 +198,7 @@ #include #include #include +#include #include #include @@ -1419,6 +1420,29 @@ command_mdtm(FTPD_SessionInfo_t *info, char const* fname) } } +static void +command_size(FTPD_SessionInfo_t *info, char const* fname) +{ + struct stat stbuf; + char buf[FTPD_BUFSIZE]; + + if(!info->auth) + { + send_reply(info, 550, "Access denied."); + return; + } + + if (info->xfer_mode != TYPE_I || 0 > stat(fname, &stbuf) || stbuf.st_size < 0) + { + send_reply(info, 550, "Could not get file size."); + } + else + { + snprintf(buf, FTPD_BUFSIZE, "%" PRIuMAX, (uintmax_t) stbuf.st_size); + send_reply(info, 213, buf); + } +} + /* * command_port * @@ -1700,6 +1724,11 @@ exec_command(FTPD_SessionInfo_t *info, char* cmd, char* args) strncpy(fname, args, 254); command_mdtm(info, fname); } + else if (!strcmp("SIZE", cmd)) + { + strncpy(fname, args, 254); + command_size(info, fname); + } else if (!strcmp("SYST", cmd)) { send_reply(info, 215, FTPD_SYSTYPE); -- cgit v1.2.3