Coding style fix.
[uftps.git] / file_stats.c
blob544c2d075d7bbc251b3363ffe49936b69d65af7d
1 /*
2 * User FTP Server
3 * Author : C2H5OH
4 * License: GPL v2
6 * file_stats.c - File status query.
8 * Here we implement some commands (SIZE, MDTM) that share the need of calling
9 * stat() over a given file, no matter the fields looked up. It's handy to merge
10 * all of them here so safety checks are not replicated.
13 #include "uftps.h"
15 void file_stats (int type)
17 int err;
18 struct stat st;
19 struct tm t;
21 if (!path_is_secure(S_arg)) {
22 send_reply(S_cmd_sk, "550 Path is insecure.\r\n");
23 return;
26 err = stat(expanded_arg(), &st);
28 if (err == -1) {
29 send_reply(S_cmd_sk, "550 Could not stat file.\r\n");
30 return;
33 switch (type) {
34 case 0: /* MDTM */
35 gmtime_r(&(st.st_mtime), &t);
36 snprintf(AuxBuf, LINE_SIZE,
37 "213 %4d%02d%02d%02d%02d%02d\r\n", t.tm_year + 1900,
38 t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
39 break;
41 case 1: /* SIZE */
42 snprintf(AuxBuf, LINE_SIZE, "213 %lld\r\n",
43 (long long) st.st_size);
46 send_reply(S_cmd_sk, AuxBuf);