Added more logging messages.
[uftps.git] / file_stats.c
blobd89d52330c32a36f8e030ea80cf0aac0f0bae767
1 /*
2 * User FTP Server, Share folders over FTP without being root.
3 * Copyright (C) 2008 Isaac Jurado
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
8 * version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "uftps.h"
22 * File status query.
24 * Here we implement some commands (SIZE, MDTM) that share the need of calling
25 * stat() over a given file, no matter the fields looked up. It's handy to
26 * merge all of them here so safety checks are not replicated.
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <time.h>
32 #include <stdio.h>
35 void file_stats (int type)
37 int err;
38 struct stat st;
39 struct tm t;
41 if (!path_is_secure(S_arg)) {
42 send_reply(S_cmd_sk, "550 Path is insecure.\r\n");
43 return;
46 err = stat(expanded_arg(), &st);
48 if (err == -1) {
49 send_reply(S_cmd_sk, "550 Could not stat file.\r\n");
50 return;
53 switch (type) {
54 case 0: /* MDTM */
55 gmtime_r(&(st.st_mtime), &t);
56 snprintf(AuxBuf, LINE_SIZE,
57 "213 %4d%02d%02d%02d%02d%02d\r\n", t.tm_year + 1900,
58 t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
59 break;
61 case 1: /* SIZE */
62 snprintf(AuxBuf, LINE_SIZE, "213 %lld\r\n",
63 (long long) st.st_size);
66 send_reply(S_cmd_sk, AuxBuf);