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
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
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
24 # include <sys/stat.h>
33 * Here we implement some commands (SIZE, MDTM) that share the need of calling
34 * stat() over a given file, no matter the fields looked up. It's handy to
35 * merge all of them here so safety checks are not replicated.
37 void file_stats (int type
)
45 warning("Stat type %d without argument", type
);
46 reply_c("501 Argument required.\r\n");
51 e
= lstat(SS
.arg
, &s
);
52 if (e
== -1 || (!S_ISREG(s
.st_mode
) && !S_ISDIR(s
.st_mode
)))
55 error("Stating file %s", SS
.arg
);
57 warning("Path %s is not file nor directory", SS
.arg
);
58 reply_c("550 Could not stat file.\r\n");
65 t
= gmtime(&s
.st_mtime
);
68 error("Converting time of %s", SS
.arg
);
69 reply_c("550 Error converting time.\r\n");
73 l
= snprintf(SS
.aux
, LINE_SIZE
, "213 %4d%02d%02d%02d%02d%02d\r\n",
74 t
->tm_year
+ 1900, t
->tm_mon
, t
->tm_mday
,
75 t
->tm_hour
, t
->tm_min
, t
->tm_sec
);
80 l
= snprintf(SS
.aux
, LINE_SIZE
, "213 %I64d\r\n", s
.st_size
);
82 l
= snprintf(SS
.aux
, LINE_SIZE
, "213 %lld\r\n",
83 (long long) s
.st_size
);