[rtems commit] ftpd: Add SIZE command

Sebastian Huber sebh at rtems.org
Wed Nov 21 15:36:30 UTC 2012


Module:    rtems
Branch:    master
Commit:    55a36b724c7cfe2ec3a4700a8588dc4ff44cb439
Changeset: http://git.rtems.org/rtems/commit/?id=55a36b724c7cfe2ec3a4700a8588dc4ff44cb439

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Nov 21 10:59:18 2012 +0100

ftpd: Add SIZE command

---

 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 905f40c..8ffd878 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);




More information about the vc mailing list