1 /* $NetBSD: ftpcmd.y,v 1.6 1995/06/03 22:46:45 mycroft Exp $ */
4 * Copyright (c) 1985, 1988, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * @(#)ftpcmd.y 8.3 (Berkeley) 4/6/94
39 * Grammar for FTP commands.
45 #include "ftpd_locl.h"
46 RCSID("$Id: ftpcmd.y 15677 2005-07-19 18:33:08Z lha $");
50 static int hasyyerrored;
55 static int cmd_bytesz;
63 short implemented; /* 1 if command is implemented */
67 extern struct tab cmdtab[];
68 extern struct tab sitetab[];
70 static char *copy (char *);
71 static void help (struct tab *, char *);
73 lookup (struct tab *, char *);
74 static void sizecmd (char *);
75 static RETSIGTYPE toolong (int);
76 static int yylex (void);
78 /* This is for bison */
80 #if !defined(alloca) && !defined(HAVE_ALLOCA)
81 #define alloca(x) malloc(x)
97 USER PASS ACCT REIN QUIT PORT
98 PASV TYPE STRU MODE RETR STOR
99 APPE MLFL MAIL MSND MSOM MSAM
100 MRSQ MRCP ALLO REST RNFR RNTO
101 ABOR DELE CWD LIST NLST SITE
102 sTAT HELP NOOP MKD RMD PWD
103 CDUP STOU SMNT SYST SIZE MDTM
108 AUTH ADAT PROT PBSZ CCC MIC
111 KAUTH KLIST KDESTROY KRBTKFILE AFSLOG
121 %type <i> check_login check_login_no_guest check_secure octal_number byte_size
122 %type <i> struct_code mode_code type_code form_code
123 %type <s> pathstring pathname password username
133 fromname = (char *) 0;
134 restart_point = (off_t) 0;
140 : USER SP username CRLF check_secure
146 | PASS SP password CRLF check_secure
150 memset ($3, 0, strlen($3));
153 | PORT SP host_port CRLF check_secure
161 reply(200, "PORT command successful.");
164 | EPRT SP STRING CRLF check_secure
170 | PASV CRLF check_login
175 | EPSV CRLF check_login
180 | EPSV SP STRING CRLF check_login
186 | TYPE SP type_code CRLF check_secure
192 if (cmd_form == FORM_N) {
193 reply(200, "Type set to A.");
197 reply(504, "Form must be N.");
201 reply(504, "Type E not implemented.");
205 reply(200, "Type set to I.");
211 if (cmd_bytesz == 8) {
213 "Type set to L (byte size 8).");
216 reply(504, "Byte size must be 8.");
217 #else /* NBBY == 8 */
218 UNIMPLEMENTED for NBBY != 8
219 #endif /* NBBY == 8 */
223 | STRU SP struct_code CRLF check_secure
229 reply(200, "STRU F ok.");
233 reply(504, "Unimplemented STRU type.");
237 | MODE SP mode_code CRLF check_secure
243 reply(200, "MODE S ok.");
247 reply(502, "Unimplemented MODE type.");
251 | ALLO SP NUMBER CRLF check_secure
254 reply(202, "ALLO command ignored.");
257 | ALLO SP NUMBER SP R SP NUMBER CRLF check_secure
260 reply(202, "ALLO command ignored.");
263 | RETR SP pathname CRLF check_login
267 if ($5 && name != NULL)
272 | STOR SP pathname CRLF check_login
276 if ($5 && name != NULL)
277 do_store(name, "w", 0);
281 | APPE SP pathname CRLF check_login
285 if ($5 && name != NULL)
286 do_store(name, "a", 0);
290 | NLST CRLF check_login
295 | NLST SP STRING CRLF check_login
299 if ($5 && name != NULL)
300 send_file_list(name);
304 | LIST CRLF check_login
309 | LIST SP pathname CRLF check_login
315 | sTAT SP pathname CRLF check_login
317 if ($5 && $3 != NULL)
322 | sTAT CRLF check_secure
327 | DELE SP pathname CRLF check_login_no_guest
329 if ($5 && $3 != NULL)
334 | RNTO SP pathname CRLF check_login_no_guest
338 renamecmd(fromname, $3);
340 fromname = (char *) 0;
342 reply(503, "Bad sequence of commands.");
348 | ABOR CRLF check_secure
351 reply(225, "ABOR command successful.");
353 | CWD CRLF check_login
358 | CWD SP pathname CRLF check_login
360 if ($5 && $3 != NULL)
365 | HELP CRLF check_secure
368 help(cmdtab, (char *) 0);
370 | HELP SP STRING CRLF check_secure
375 if (strncasecmp(cp, "SITE", 4) == 0) {
382 help(sitetab, (char *) 0);
387 | NOOP CRLF check_secure
390 reply(200, "NOOP command successful.");
392 | MKD SP pathname CRLF check_login
394 if ($5 && $3 != NULL)
399 | RMD SP pathname CRLF check_login_no_guest
401 if ($5 && $3 != NULL)
406 | PWD CRLF check_login
411 | CDUP CRLF check_login
416 | FEAT CRLF check_secure
419 lreply(211, "Supported features:");
421 lreply(0, " REST STREAM");
426 | OPTS SP STRING CRLF check_secure
429 reply(501, "Bad options");
433 | SITE SP HELP CRLF check_secure
436 help(sitetab, (char *) 0);
438 | SITE SP HELP SP STRING CRLF check_secure
443 | SITE SP UMASK CRLF check_login
446 int oldmask = umask(0);
448 reply(200, "Current UMASK is %03o", oldmask);
451 | SITE SP UMASK SP octal_number CRLF check_login_no_guest
454 if (($5 == -1) || ($5 > 0777)) {
455 reply(501, "Bad UMASK value");
457 int oldmask = umask($5);
459 "UMASK set to %03o (was %03o)",
464 | SITE SP CHMOD SP octal_number SP pathname CRLF check_login_no_guest
466 if ($9 && $7 != NULL) {
469 "CHMOD: Mode value must be between 0 and 0777");
470 else if (chmod($7, $5) < 0)
471 perror_reply(550, $7);
473 reply(200, "CHMOD command successful.");
478 | SITE SP IDLE CRLF check_secure
482 "Current IDLE time limit is %d seconds; max %d",
483 ftpd_timeout, maxtimeout);
485 | SITE SP IDLE SP NUMBER CRLF check_secure
488 if ($5 < 30 || $5 > maxtimeout) {
490 "Maximum IDLE time must be between 30 and %d seconds",
494 alarm((unsigned) ftpd_timeout);
496 "Maximum IDLE time set to %d seconds",
502 | SITE SP KAUTH SP STRING CRLF check_login
508 reply(500, "Can't be done as guest.");
510 if($7 && $5 != NULL){
511 p = strpbrk($5, " \t");
514 kauth($5, p + strspn(p, " \t"));
522 reply(500, "Command not implemented.");
525 | SITE SP KLIST CRLF check_login
530 | SITE SP KDESTROY CRLF check_login
536 reply(500, "Command not implemented.");
539 | SITE SP KRBTKFILE SP STRING CRLF check_login
543 reply(500, "Can't be done as guest.");
549 reply(500, "Command not implemented.");
552 | SITE SP AFSLOG CRLF check_login
554 #if defined(KRB4) || defined(KRB5)
556 reply(500, "Can't be done as guest.");
560 reply(500, "Command not implemented.");
563 | SITE SP AFSLOG SP STRING CRLF check_login
565 #if defined(KRB4) || defined(KRB5)
567 reply(500, "Can't be done as guest.");
573 reply(500, "Command not implemented.");
576 | SITE SP LOCATE SP STRING CRLF check_login
583 | SITE SP URL CRLF check_secure
586 reply(200, "http://www.pdc.kth.se/heimdal/");
588 | STOU SP pathname CRLF check_login
590 if ($5 && $3 != NULL)
591 do_store($3, "w", 1);
595 | SYST CRLF check_secure
598 #if !defined(WIN32) && !defined(__EMX__) && !defined(__OS2__) && !defined(__CYGWIN32__)
599 reply(215, "UNIX Type: L%d", NBBY);
601 reply(215, "UNKNOWN Type: L%d", NBBY);
607 * SIZE is not in RFC959, but Postel has blessed it and
608 * it will be in the updated RFC.
610 * Return size of file in a format suitable for
611 * using with RESTART (we just count bytes).
613 | SIZE SP pathname CRLF check_login
615 if ($5 && $3 != NULL)
622 * MDTM is not in RFC959, but Postel has blessed it and
623 * it will be in the updated RFC.
625 * Return modification time of file as an ISO 3307
626 * style time. E.g. YYYYMMDDHHMMSS or YYYYMMDDHHMMSS.xxx
627 * where xxx is the fractional second (of any precision,
628 * not necessarily 3 digits)
630 | MDTM SP pathname CRLF check_login
632 if ($5 && $3 != NULL) {
634 if (stat($3, &stbuf) < 0)
636 $3, strerror(errno));
637 else if (!S_ISREG(stbuf.st_mode)) {
639 "%s: not a plain file.", $3);
642 time_t mtime = stbuf.st_mtime;
646 "%04d%02d%02d%02d%02d%02d",
658 | QUIT CRLF check_secure
661 reply(221, "Goodbye.");
671 : RNFR SP pathname CRLF check_login_no_guest
673 restart_point = (off_t) 0;
675 fromname = renamefrom($3);
676 if (fromname == (char *) 0 && $3) {
681 | REST SP byte_size CRLF check_secure
684 fromname = (char *) 0;
685 restart_point = $3; /* XXX $3 is only "int" */
686 reply(350, "Restarting at %ld. %s",
688 "Send STORE or RETRIEVE to initiate transfer.");
691 | AUTH SP STRING CRLF
696 | ADAT SP STRING CRLF
701 | PBSZ SP NUMBER CRLF check_secure
706 | PROT SP STRING CRLF check_secure
711 | CCC CRLF check_secure
721 | CONF SP STRING CRLF
723 mec($3, prot_confidential);
728 mec($3, prot_private);
740 $$ = (char *)calloc(1, sizeof(char));
750 : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA
753 struct sockaddr_in *sin4 = (struct sockaddr_in *)data_dest;
755 sin4->sin_family = AF_INET;
756 sin4->sin_port = htons($9 * 256 + $11);
757 sin4->sin_addr.s_addr =
758 htonl(($1 << 24) | ($3 << 16) | ($5 << 8) | $7);
812 /* this is for a bug in the BBN ftp */
854 * Problem: this production is used for all pathname
855 * processing, but only gives a 550 error reply.
856 * This is a valid reply in some cases but not in others.
858 if (logged_in && $1 && *$1 == '~') {
861 GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
863 memset(&gl, 0, sizeof(gl));
864 if (glob($1, flags, NULL, &gl) ||
866 reply(550, "not found");
869 $$ = strdup(gl.gl_pathv[0]);
885 int ret, dec, multby, digit;
888 * Convert a number that was read as decimal number
889 * to what it would be if it had been read as octal.
900 ret += digit * multby;
909 check_login_no_guest : check_login
913 reply(550, "Permission denied");
917 check_login : check_secure
920 if(($$ = logged_in) == 0)
921 reply(530, "Please login with USER and PASS.");
927 check_secure : /* empty */
930 if(sec_complete && !ccc_passed && !secure_command()) {
932 reply(533, "Command protection level denied "
933 "for paranoid reasons.");
940 #define CMD 0 /* beginning of command */
941 #define ARGS 1 /* expect miscellaneous arguments */
942 #define STR1 2 /* expect SP followed by STRING */
943 #define STR2 3 /* expect STRING */
944 #define OSTR 4 /* optional SP then STRING */
945 #define ZSTR1 5 /* SP then optional STRING */
946 #define ZSTR2 6 /* optional STRING after SP */
947 #define SITECMD 7 /* SITE command */
948 #define NSTR 8 /* Number followed by a string */
950 struct tab cmdtab[] = { /* In order defined in RFC 765 */
951 { "USER", USER, STR1, 1, "<sp> username" },
952 { "PASS", PASS, ZSTR1, 1, "<sp> password" },
953 { "ACCT", ACCT, STR1, 0, "(specify account)" },
954 { "SMNT", SMNT, ARGS, 0, "(structure mount)" },
955 { "REIN", REIN, ARGS, 0, "(reinitialize server state)" },
956 { "QUIT", QUIT, ARGS, 1, "(terminate service)", },
957 { "PORT", PORT, ARGS, 1, "<sp> b0, b1, b2, b3, b4" },
958 { "EPRT", EPRT, STR1, 1, "<sp> string" },
959 { "PASV", PASV, ARGS, 1, "(set server in passive mode)" },
960 { "EPSV", EPSV, OSTR, 1, "[<sp> foo]" },
961 { "TYPE", TYPE, ARGS, 1, "<sp> [ A | E | I | L ]" },
962 { "STRU", STRU, ARGS, 1, "(specify file structure)" },
963 { "MODE", MODE, ARGS, 1, "(specify transfer mode)" },
964 { "RETR", RETR, STR1, 1, "<sp> file-name" },
965 { "STOR", STOR, STR1, 1, "<sp> file-name" },
966 { "APPE", APPE, STR1, 1, "<sp> file-name" },
967 { "MLFL", MLFL, OSTR, 0, "(mail file)" },
968 { "MAIL", MAIL, OSTR, 0, "(mail to user)" },
969 { "MSND", MSND, OSTR, 0, "(mail send to terminal)" },
970 { "MSOM", MSOM, OSTR, 0, "(mail send to terminal or mailbox)" },
971 { "MSAM", MSAM, OSTR, 0, "(mail send to terminal and mailbox)" },
972 { "MRSQ", MRSQ, OSTR, 0, "(mail recipient scheme question)" },
973 { "MRCP", MRCP, STR1, 0, "(mail recipient)" },
974 { "ALLO", ALLO, ARGS, 1, "allocate storage (vacuously)" },
975 { "REST", REST, ARGS, 1, "<sp> offset (restart command)" },
976 { "RNFR", RNFR, STR1, 1, "<sp> file-name" },
977 { "RNTO", RNTO, STR1, 1, "<sp> file-name" },
978 { "ABOR", ABOR, ARGS, 1, "(abort operation)" },
979 { "DELE", DELE, STR1, 1, "<sp> file-name" },
980 { "CWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
981 { "XCWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
982 { "LIST", LIST, OSTR, 1, "[ <sp> path-name ]" },
983 { "NLST", NLST, OSTR, 1, "[ <sp> path-name ]" },
984 { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" },
985 { "SYST", SYST, ARGS, 1, "(get type of operating system)" },
986 { "STAT", sTAT, OSTR, 1, "[ <sp> path-name ]" },
987 { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
988 { "NOOP", NOOP, ARGS, 1, "" },
989 { "MKD", MKD, STR1, 1, "<sp> path-name" },
990 { "XMKD", MKD, STR1, 1, "<sp> path-name" },
991 { "RMD", RMD, STR1, 1, "<sp> path-name" },
992 { "XRMD", RMD, STR1, 1, "<sp> path-name" },
993 { "PWD", PWD, ARGS, 1, "(return current directory)" },
994 { "XPWD", PWD, ARGS, 1, "(return current directory)" },
995 { "CDUP", CDUP, ARGS, 1, "(change to parent directory)" },
996 { "XCUP", CDUP, ARGS, 1, "(change to parent directory)" },
997 { "STOU", STOU, STR1, 1, "<sp> file-name" },
998 { "SIZE", SIZE, OSTR, 1, "<sp> path-name" },
999 { "MDTM", MDTM, OSTR, 1, "<sp> path-name" },
1001 /* extensions from RFC2228 */
1002 { "AUTH", AUTH, STR1, 1, "<sp> auth-type" },
1003 { "ADAT", ADAT, STR1, 1, "<sp> auth-data" },
1004 { "PBSZ", PBSZ, ARGS, 1, "<sp> buffer-size" },
1005 { "PROT", PROT, STR1, 1, "<sp> prot-level" },
1006 { "CCC", CCC, ARGS, 1, "" },
1007 { "MIC", MIC, STR1, 1, "<sp> integrity command" },
1008 { "CONF", CONF, STR1, 1, "<sp> confidentiality command" },
1009 { "ENC", ENC, STR1, 1, "<sp> privacy command" },
1012 { "FEAT", FEAT, ARGS, 1, "" },
1013 { "OPTS", OPTS, ARGS, 1, "<sp> command [<sp> options]" },
1015 { NULL, 0, 0, 0, 0 }
1018 struct tab sitetab[] = {
1019 { "UMASK", UMASK, ARGS, 1, "[ <sp> umask ]" },
1020 { "IDLE", IDLE, ARGS, 1, "[ <sp> maximum-idle-time ]" },
1021 { "CHMOD", CHMOD, NSTR, 1, "<sp> mode <sp> file-name" },
1022 { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
1024 { "KAUTH", KAUTH, STR1, 1, "<sp> principal [ <sp> ticket ]" },
1025 { "KLIST", KLIST, ARGS, 1, "(show ticket file)" },
1026 { "KDESTROY", KDESTROY, ARGS, 1, "(destroy tickets)" },
1027 { "KRBTKFILE", KRBTKFILE, STR1, 1, "<sp> ticket-file" },
1028 { "AFSLOG", AFSLOG, OSTR, 1, "[<sp> cell]" },
1030 { "LOCATE", LOCATE, STR1, 1, "<sp> globexpr" },
1031 { "FIND", LOCATE, STR1, 1, "<sp> globexpr" },
1033 { "URL", URL, ARGS, 1, "?" },
1035 { NULL, 0, 0, 0, 0 }
1039 lookup(struct tab *p, char *cmd)
1042 for (; p->name != NULL; p++)
1043 if (strcmp(cmd, p->name) == 0)
1049 * ftpd_getline - a hacked up version of fgets to ignore TELNET escape codes.
1052 ftpd_getline(char *s, int n)
1059 /* might still be data within the security MIC/CONF/ENC */
1061 strlcpy(s, ftp_command, n);
1063 syslog(LOG_DEBUG, "command: %s", s);
1066 while ((c = getc(stdin)) != EOF) {
1069 if ((c = getc(stdin)) != EOF) {
1075 printf("%c%c%c", IAC, DONT, 0377&c);
1081 printf("%c%c%c", IAC, WONT, 0377&c);
1087 continue; /* ignore command */
1092 if (--n <= 0 || c == '\n')
1095 if (c == EOF && cs == s)
1099 if (!guest && strncasecmp("pass ", s, 5) == 0) {
1100 /* Don't syslog passwords */
1101 syslog(LOG_DEBUG, "command: %.5s ???", s);
1106 /* Don't syslog trailing CR-LF */
1109 while (cp >= s && (*cp == '\n' || *cp == '\r')) {
1113 syslog(LOG_DEBUG, "command: %.*s", len, s);
1117 fprintf(stderr, "%s\n", s);
1127 "Timeout (%d seconds): closing control connection.",
1130 syslog(LOG_INFO, "User %s timed out after %d seconds",
1131 (pw ? pw -> pw_name : "unknown"), ftpd_timeout);
1139 static int cpos, state;
1151 signal(SIGALRM, toolong);
1152 alarm((unsigned) ftpd_timeout);
1153 if (ftpd_getline(cbuf, sizeof(cbuf)-1) == NULL) {
1154 reply(221, "You could at least say goodbye.");
1158 #ifdef HAVE_SETPROCTITLE
1159 if (strncasecmp(cbuf, "PASS", 4) != 0)
1160 setproctitle("%s: %s", proctitle, cbuf);
1161 #endif /* HAVE_SETPROCTITLE */
1162 if ((cp = strchr(cbuf, '\r'))) {
1166 if ((cp = strpbrk(cbuf, " \n")))
1173 p = lookup(cmdtab, cbuf);
1176 if (p->implemented == 0) {
1188 if (cbuf[cpos] == ' ') {
1193 if ((cp2 = strpbrk(cp, " \n")))
1198 p = lookup(sitetab, cp);
1201 if (p->implemented == 0) {
1215 if (cbuf[cpos] == '\n') {
1224 if (cbuf[cpos] == ' ') {
1235 if (cbuf[cpos] == '\n') {
1246 * Make sure the string is nonempty and \n terminated.
1248 if (n > 1 && cbuf[cpos] == '\n') {
1250 yylval.s = copy(cp);
1258 if (cbuf[cpos] == ' ') {
1262 if (isdigit((unsigned char)cbuf[cpos])) {
1264 while (isdigit((unsigned char)cbuf[++cpos]))
1268 yylval.i = atoi(cp);
1277 if (isdigit((unsigned char)cbuf[cpos])) {
1279 while (isdigit((unsigned char)cbuf[++cpos]))
1283 yylval.i = atoi(cp);
1287 switch (cbuf[cpos++]) {
1351 fatal("Unknown state in scanner.");
1368 if ((cp = strchr(cbuf,'\n')))
1370 reply(500, "'%s': command not understood.", cbuf);
1381 fatal("Ran out of memory.");
1386 help(struct tab *ctab, char *s)
1393 if (ctab == sitetab)
1397 width = 0, NCMDS = 0;
1398 for (c = ctab; c->name != NULL; c++) {
1399 int len = strlen(c->name);
1405 width = (width + 8) &~ 7;
1410 lreply(214, "The following %scommands are recognized %s.",
1411 t, "(* =>'s unimplemented)");
1412 columns = 76 / width;
1415 lines = (NCMDS + columns - 1) / columns;
1416 for (i = 0; i < lines; i++) {
1417 strlcpy (buf, " ", sizeof(buf));
1418 for (j = 0; j < columns; j++) {
1419 c = ctab + j * lines + i;
1420 snprintf (buf + strlen(buf),
1421 sizeof(buf) - strlen(buf),
1424 c->implemented ? ' ' : '*');
1425 if (c + lines >= &ctab[NCMDS])
1427 w = strlen(c->name) + 1;
1435 lreply(214, "%s", buf);
1437 reply(214, "Direct comments to kth-krb-bugs@pdc.kth.se");
1441 c = lookup(ctab, s);
1442 if (c == (struct tab *)0) {
1443 reply(502, "Unknown command %s.", s);
1447 reply(214, "Syntax: %s%s %s", t, c->name, c->help);
1449 reply(214, "%s%-*s\t%s; unimplemented.", t, width,
1454 sizecmd(char *filename)
1460 if (stat(filename, &stbuf) < 0 || !S_ISREG(stbuf.st_mode))
1461 reply(550, "%s: not a plain file.", filename);
1463 reply(213, "%lu", (unsigned long)stbuf.st_size);
1471 fin = fopen(filename, "r");
1473 perror_reply(550, filename);
1476 if (fstat(fileno(fin), &stbuf) < 0 || !S_ISREG(stbuf.st_mode)) {
1477 reply(550, "%s: not a plain file.", filename);
1483 while((c=getc(fin)) != EOF) {
1484 if (c == '\n') /* will get expanded to \r\n */
1490 reply(213, "%lu", (unsigned long)count);
1494 reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);