diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2012-11-21 10:59:18 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2012-11-21 16:38:34 +0100 |
commit | 55a36b724c7cfe2ec3a4700a8588dc4ff44cb439 (patch) | |
tree | 918faae683e82cde8ea44d55d3e93d905a88a948 | |
parent | sptests/spcbssched02: PR2081: Workaround (diff) | |
download | rtems-55a36b724c7cfe2ec3a4700a8588dc4ff44cb439.tar.bz2 |
ftpd: Add SIZE command
-rw-r--r-- | cpukit/ftpd/ftpd.c | 29 |
1 files changed, 29 insertions, 0 deletions
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 <dirent.h> #include <errno.h> #include <ctype.h> +#include <inttypes.h> #include <rtems.h> #include <rtems/rtems_bsdnet.h> @@ -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); |