1 /* vi: set sw=4 ts=4: */
3 * Simple FTP daemon, based on vsftpd 2.0.7 (written by Chris Evans)
5 * Author: Adam Tkac <vonsch@gmail.com>
7 * Only subset of FTP protocol is implemented but vast majority of clients
8 * should not have any problem. You have to run this daemon via inetd.
11 * -w - enable FTP write commands
16 #include <netinet/tcp.h>
30 FTP_STATFILE_OK = 213,
47 FTP_BADSENDCONN = 425,
49 FTP_BADSENDFILE = 451,
51 FTP_COMMANDNOTIMPL = 502,
61 #define mk_const4(a,b,c,d) (((a * 0x100 + b) * 0x100 + c) * 0x100 + d)
62 #define mk_const3(a,b,c) ((a * 0x100 + b) * 0x100 + c)
63 const_ALLO = mk_const4('A', 'L', 'L', 'O'),
64 const_APPE = mk_const4('A', 'P', 'P', 'E'),
65 const_CDUP = mk_const4('C', 'D', 'U', 'P'),
66 const_CWD = mk_const3('C', 'W', 'D'),
67 const_DELE = mk_const4('D', 'E', 'L', 'E'),
68 const_HELP = mk_const4('H', 'E', 'L', 'P'),
69 const_LIST = mk_const4('L', 'I', 'S', 'T'),
70 const_MKD = mk_const3('M', 'K', 'D'),
71 const_MODE = mk_const4('M', 'O', 'D', 'E'),
72 const_NLST = mk_const4('N', 'L', 'S', 'T'),
73 const_NOOP = mk_const4('N', 'O', 'O', 'P'),
74 const_PASS = mk_const4('P', 'A', 'S', 'S'),
75 const_PASV = mk_const4('P', 'A', 'S', 'V'),
76 const_PORT = mk_const4('P', 'O', 'R', 'T'),
77 const_PWD = mk_const3('P', 'W', 'D'),
78 const_QUIT = mk_const4('Q', 'U', 'I', 'T'),
79 const_REST = mk_const4('R', 'E', 'S', 'T'),
80 const_RETR = mk_const4('R', 'E', 'T', 'R'),
81 const_RMD = mk_const3('R', 'M', 'D'),
82 const_RNFR = mk_const4('R', 'N', 'F', 'R'),
83 const_RNTO = mk_const4('R', 'N', 'T', 'O'),
84 const_STAT = mk_const4('S', 'T', 'A', 'T'),
85 const_STOR = mk_const4('S', 'T', 'O', 'R'),
86 const_STOU = mk_const4('S', 'T', 'O', 'U'),
87 const_STRU = mk_const4('S', 'T', 'R', 'U'),
88 const_SYST = mk_const4('S', 'Y', 'S', 'T'),
89 const_TYPE = mk_const4('T', 'Y', 'P', 'E'),
90 const_USER = mk_const4('U', 'S', 'E', 'R'),
94 char *p_control_line_buf;
95 len_and_sockaddr *local_addr;
96 len_and_sockaddr *port_addr;
102 #if ENABLE_FEATURE_FTP_WRITE
107 #define G (*(struct globals*)&bb_common_bufsiz1)
108 #define INIT_G() do { } while (0)
113 xwrite_str(int fd, const char *str)
115 xwrite(fd, str, strlen(str));
119 replace_text(const char *str, const char from, const char *to)
121 size_t retlen, remainlen, chunklen, tolen;
126 remainlen = strlen(str);
129 /* Simply alloc strlen(str)*strlen(to). "to" is max 2 so it's ok */
130 ret = xmalloc(remainlen * tolen + 1);
134 found = strchr(remain, from);
136 chunklen = found - remain;
138 /* Copy chunk which doesn't contain 'from' to ret */
139 memcpy(&ret[retlen], remain, chunklen);
142 /* Now copy 'to' instead of 'from' */
143 memcpy(&ret[retlen], to, tolen);
149 * The last chunk. We are already sure that we have enough space
150 * so we can use strcpy.
152 strcpy(&ret[retlen], remain);
160 replace_char(char *str, char from, char to)
162 while ((str = strchr(str, from)) != NULL)
167 ftp_write_str_common(unsigned int status, const char *str, char sep)
169 char *escaped_str, *response;
172 escaped_str = replace_text(str, '\377', "\377\377");
174 response = xasprintf("%u%c%s\r\n", status, sep, escaped_str);
177 len = strlen(response);
178 replace_char(response, '\n', '\0');
180 /* Change trailing '\0' back to '\n' */
181 response[len - 1] = '\n';
182 xwrite(STDIN_FILENO, response, len);
186 cmdio_write(int status, const char *p_text)
188 ftp_write_str_common(status, p_text, ' ');
192 cmdio_write_ok(int status)
194 ftp_write_str_common(status, "Operation successful", ' ');
198 cmdio_write_hyphen(int status, const char *p_text)
200 ftp_write_str_common(status, p_text, '-');
204 cmdio_write_raw(const char *p_text)
206 xwrite_str(STDIN_FILENO, p_text);
210 cmdio_get_cmd_and_arg(void)
217 len = 8 * 1024; /* Paranoia. Peer may send 1 gigabyte long cmd... */
218 G.ftp_cmp = cmd = xmalloc_reads(STDIN_FILENO, NULL, &len);
222 len = strlen(cmd) - 1;
223 while (len >= 0 && cmd[len] == '\r') {
228 G.ftp_arg = strchr(cmd, ' ');
229 if (G.ftp_arg != NULL) {
230 *(char *)G.ftp_arg = '\0';
235 cmdval = (cmdval << 8) + ((unsigned char)*cmd++ & (unsigned char)~0x20);
241 init_data_sock_params(int sock_fd)
243 struct linger linger;
247 memset(&linger, 0, sizeof(linger));
249 linger.l_linger = 32767;
251 setsockopt(sock_fd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
252 setsockopt(sock_fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
256 ftpdataio_get_pasv_fd(void)
260 remote_fd = accept(G.pasv_listen_fd, NULL, 0);
263 cmdio_write(FTP_BADSENDCONN, "Can't establish connection");
267 init_data_sock_params(remote_fd);
272 ftpdataio_get_port_fd(void)
276 /* Do we want die or print error to client? */
277 remote_fd = xconnect_stream(G.port_addr);
279 init_data_sock_params(remote_fd);
284 ftpdataio_dispose_transfer_fd(void)
286 /* This close() blocks because we set SO_LINGER */
287 if (G.data_fd > STDOUT_FILENO) {
288 if (close(G.data_fd) < 0) {
289 /* Do it again without blocking. */
290 struct linger linger;
292 memset(&linger, 0, sizeof(linger));
293 setsockopt(G.data_fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
303 return (G.port_addr != NULL) ? 1: 0;
309 return (G.pasv_listen_fd != -1) ? 1 : 0;
313 get_remote_transfer_fd(const char *p_status_msg)
318 remote_fd = ftpdataio_get_pasv_fd();
320 remote_fd = ftpdataio_get_port_fd();
325 cmdio_write(FTP_DATACONN, p_status_msg);
332 char *cwd, *promoted_cwd, *response;
334 cwd = xrealloc_getcwd_or_warn(NULL);
338 /* We have to promote each " to "" */
339 promoted_cwd = replace_text(cwd, '\"', "\"\"");
341 response = xasprintf("\"%s\"", promoted_cwd);
343 cmdio_write(FTP_PWDOK, response);
350 if (!G.ftp_arg || chdir(G.ftp_arg) != 0) {
351 cmdio_write(FTP_FILEFAIL, "Can't change directory");
354 cmdio_write_ok(FTP_CWDOK);
365 data_transfer_checks_ok(void)
367 if (!pasv_active() && !port_active()) {
368 cmdio_write(FTP_BADSENDCONN, "Use PORT or PASV first");
385 if (G.pasv_listen_fd > STDOUT_FILENO)
386 close(G.pasv_listen_fd);
387 G.pasv_listen_fd = -1;
393 int bind_retries = 10;
395 enum { min_port = 1024, max_port = 65535 };
396 char *addr, *wire_addr, *response;
400 G.pasv_listen_fd = xsocket(G.local_addr->u.sa.sa_family, SOCK_STREAM, 0);
401 setsockopt_reuseaddr(G.pasv_listen_fd);
403 /* TODO bind() with port == 0 and then call getsockname */
404 while (--bind_retries) {
405 port = rand() % max_port;
406 if (port < min_port) {
410 set_nport(G.local_addr, htons(port));
411 /* We don't want to use xbind, it'll die if port is in use */
412 if (bind(G.pasv_listen_fd, &G.local_addr->u.sa, G.local_addr->len) != 0) {
413 /* do we want check if errno == EADDRINUSE ? */
416 xlisten(G.pasv_listen_fd, 1);
421 bb_error_msg_and_die("can't create pasv socket");
423 addr = xmalloc_sockaddr2dotted_noport(&G.local_addr->u.sa);
424 wire_addr = replace_text(addr, '.', ",");
427 response = xasprintf("Entering Passive Mode (%s,%u,%u)",
428 wire_addr, (int)(port >> 8), (int)(port & 255));
430 cmdio_write(FTP_PASVOK, response);
439 char *raw = NULL, *port_part;
440 len_and_sockaddr *lsa = NULL;
445 if (G.ftp_arg == NULL)
448 raw = replace_text(G.ftp_arg, ',', ".");
450 port_part = strrchr(raw, '.');
451 if (port_part == NULL)
454 port = xatou16(&port_part[1]);
457 port_part = strrchr(raw, '.');
458 if (port_part == NULL)
461 port |= xatou16(&port_part[1]) << 8;
464 lsa = xdotted2sockaddr(raw, port);
470 cmdio_write(FTP_BADCMD, "Illegal PORT command");
475 cmdio_write_ok(FTP_PORTOK);
481 /* When ftp_arg == NULL simply restart from beginning */
482 G.restart_pos = G.ftp_arg ? xatoi_u(G.ftp_arg) : 0;
483 cmdio_write_ok(FTP_RESTOK);
490 int trans_ret, retval;
493 off_t offset = G.restart_pos;
498 if (!data_transfer_checks_ok())
501 /* O_NONBLOCK is useful if file happens to be a device node */
502 opened_file = G.ftp_arg ? open(G.ftp_arg, O_RDONLY | O_NONBLOCK) : -1;
503 if (opened_file < 0) {
504 cmdio_write(FTP_FILEFAIL, "Can't open file");
508 retval = fstat(opened_file, &statbuf);
509 if (retval < 0 || !S_ISREG(statbuf.st_mode)) {
510 /* Note - pretend open failed */
511 cmdio_write(FTP_FILEFAIL, "Can't open file");
515 /* Now deactive O_NONBLOCK, otherwise we have a problem on DMAPI filesystems
518 ndelay_off(opened_file);
520 /* Set the download offset (from REST) if any */
522 xlseek(opened_file, offset, SEEK_SET);
524 response = xasprintf(
525 "Opening BINARY mode data connection for %s (%"OFF_FMT"u bytes)",
526 G.ftp_arg, statbuf.st_size);
527 remote_fd = get_remote_transfer_fd(response);
530 goto port_pasv_cleanup_out;
532 trans_ret = bb_copyfd_eof(opened_file, remote_fd);
533 ftpdataio_dispose_transfer_fd();
535 cmdio_write(FTP_BADSENDFILE, "Error sending local file");
537 cmdio_write_ok(FTP_TRANSFEROK);
539 port_pasv_cleanup_out:
547 statbuf_getperms(const struct stat *statbuf)
550 enum { r = 'r', w = 'w', x = 'x', s = 's', S = 'S' };
553 memset(perms, '-', 10);
556 switch (statbuf->st_mode & S_IFMT) {
557 case S_IFREG: perms[0] = '-'; break;
558 case S_IFDIR: perms[0] = 'd'; break;
559 case S_IFLNK: perms[0] = 'l'; break;
560 case S_IFIFO: perms[0] = 'p'; break;
561 case S_IFSOCK: perms[0] = s; break;
562 case S_IFCHR: perms[0] = 'c'; break;
563 case S_IFBLK: perms[0] = 'b'; break;
566 if (statbuf->st_mode & S_IRUSR) perms[1] = r;
567 if (statbuf->st_mode & S_IWUSR) perms[2] = w;
568 if (statbuf->st_mode & S_IXUSR) perms[3] = x;
569 if (statbuf->st_mode & S_IRGRP) perms[4] = r;
570 if (statbuf->st_mode & S_IWGRP) perms[5] = w;
571 if (statbuf->st_mode & S_IXGRP) perms[6] = x;
572 if (statbuf->st_mode & S_IROTH) perms[7] = r;
573 if (statbuf->st_mode & S_IWOTH) perms[8] = w;
574 if (statbuf->st_mode & S_IXOTH) perms[9] = x;
575 if (statbuf->st_mode & S_ISUID) perms[3] = (perms[3] == x) ? s : S;
576 if (statbuf->st_mode & S_ISGID) perms[6] = (perms[6] == x) ? s : S;
577 if (statbuf->st_mode & S_ISVTX) perms[9] = (perms[9] == x) ? 't' : 'T';
585 write_filestats(int fd, const char *filename,
586 const struct stat *statbuf)
589 char *stats, *lnkname = NULL, *perms;
594 const char *format = "%b %d %H:%M";
596 name = bb_get_last_path_component_nostrip(filename);
598 if (statbuf != NULL) {
599 size = statbuf->st_size;
601 if (S_ISLNK(statbuf->st_mode))
602 /* Damn symlink... */
603 lnkname = xmalloc_readlink(filename);
605 tm = gmtime(&statbuf->st_mtime);
606 retval = strftime(timestr, sizeof(timestr), format, tm);
608 bb_error_msg_and_die("strftime");
610 timestr[sizeof(timestr) - 1] = '\0';
612 perms = statbuf_getperms(statbuf);
614 stats = xasprintf("%s %u\tftp ftp %"OFF_FMT"u\t%s %s",
615 perms, (int) statbuf->st_nlink,
616 size, timestr, name);
620 stats = xstrdup(name);
622 xwrite_str(fd, stats);
624 if (lnkname != NULL) {
625 xwrite_str(fd, " -> ");
626 xwrite_str(fd, lnkname);
629 xwrite_str(fd, "\r\n");
633 write_dirstats(int fd, const char *dname, int details)
636 struct dirent *dirent;
640 dir = xopendir(dname);
643 dirent = readdir(dir);
647 /* Ignore . and .. */
648 if (dirent->d_name[0] == '.') {
649 if (dirent->d_name[1] == '\0'
650 || (dirent->d_name[1] == '.' && dirent->d_name[2] == '\0')
657 filename = xasprintf("%s/%s", dname, dirent->d_name);
658 if (lstat(filename, &statbuf) != 0) {
663 filename = xstrdup(dirent->d_name);
665 write_filestats(fd, filename, details ? &statbuf : NULL);
673 handle_dir_common(int full_details, int stat_cmd)
678 if (!stat_cmd && !data_transfer_checks_ok())
683 cmdio_write_hyphen(FTP_STATFILE_OK, "Status follows:");
685 fd = get_remote_transfer_fd("Here comes the directory listing");
691 if (lstat(G.ftp_arg, &statbuf) != 0) {
692 /* Dir doesn't exist => return ok to client */
695 if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode))
696 write_filestats(fd, G.ftp_arg, &statbuf);
697 else if (S_ISDIR(statbuf.st_mode))
698 write_dirstats(fd, G.ftp_arg, full_details);
700 write_dirstats(fd, ".", full_details);
703 /* Well, if we can't open directory/file it doesn't matter */
705 ftpdataio_dispose_transfer_fd();
708 cmdio_write_ok(FTP_TRANSFEROK);
710 cmdio_write_ok(FTP_STATFILE_OK);
716 handle_dir_common(1, 0);
722 handle_dir_common(0, 0);
726 handle_stat_file(void)
728 handle_dir_common(1, 1);
734 cmdio_write_hyphen(FTP_STATOK, "FTP server status:");
735 cmdio_write_raw(" TYPE: BINARY\r\n");
736 cmdio_write_ok(FTP_STATOK);
743 && ( ((G.ftp_arg[0] | 0x20) == 'i' && G.ftp_arg[1] == '\0')
744 || !strcasecmp(G.ftp_arg, "L8")
745 || !strcasecmp(G.ftp_arg, "L 8")
748 cmdio_write_ok(FTP_TYPEOK);
750 cmdio_write(FTP_BADCMD, "Unrecognised TYPE command");
757 cmdio_write_hyphen(FTP_HELP, "Recognized commands:");
758 cmdio_write_raw(" ALLO CDUP CWD HELP LIST\r\n"
759 " MODE NLST NOOP PASS PASV PORT PWD QUIT\r\n"
760 " REST RETR STAT STRU SYST TYPE USER\r\n"
761 #if ENABLE_FEATURE_FTP_WRITE
762 " APPE DELE MKD RMD RNFR RNTO STOR STOU\r\n"
765 cmdio_write(FTP_HELP, "Help OK");
768 #if ENABLE_FEATURE_FTP_WRITE
770 handle_upload_common(int is_append, int is_unique)
772 char *tempname = NULL;
776 off_t offset = G.restart_pos;
779 if (!G.ftp_arg || !data_transfer_checks_ok())
783 tempname = xstrdup("FILE: uniq.XXXXXX");
785 * XXX Use mkostemp here? vsftpd opens file with O_CREAT, O_WRONLY,
786 * O_APPEND and O_EXCL flags...
788 new_file_fd = mkstemp(tempname + 6);
790 /* XXX Do we need check if ftp_arg != NULL? */
791 if (!is_append && offset == 0)
792 new_file_fd = open(G.ftp_arg, O_CREAT | O_WRONLY | O_APPEND | O_NONBLOCK | O_TRUNC, 0666);
794 new_file_fd = open(G.ftp_arg, O_CREAT | O_WRONLY | O_APPEND | O_NONBLOCK, 0666);
797 if (new_file_fd < 0) {
798 cmdio_write(FTP_UPLOADFAIL, "Can't create file");
802 if (!is_append && offset != 0) {
803 /* warning, allows seek past end of file! Check for seek > size? */
804 xlseek(new_file_fd, offset, SEEK_SET);
808 remote_fd = get_remote_transfer_fd(tempname);
811 remote_fd = get_remote_transfer_fd("Ok to send data");
816 trans_ret = bb_copyfd_eof(remote_fd, new_file_fd);
817 ftpdataio_dispose_transfer_fd();
820 cmdio_write(FTP_BADSENDFILE, "Failure writing to local file");
822 cmdio_write_ok(FTP_TRANSFEROK);
833 if (!G.ftp_arg || mkdir(G.ftp_arg, 0777) != 0) {
834 cmdio_write(FTP_FILEFAIL, "Create directory operation failed");
837 cmdio_write_ok(FTP_MKDIROK);
843 if (!G.ftp_arg || rmdir(G.ftp_arg) != 0) {
844 cmdio_write(FTP_FILEFAIL, "Deletion failed");
847 cmdio_write_ok(FTP_RMDIROK);
853 if (!G.ftp_arg || unlink(G.ftp_arg) != 0) {
854 cmdio_write(FTP_FILEFAIL, "Deletion failed");
857 cmdio_write_ok(FTP_DELEOK);
865 /* Clear old value */
866 free(G.rnfr_filename);
867 G.rnfr_filename = NULL;
870 || stat(G.ftp_arg, &statbuf) != 0
871 /* || it isn't a regular file or a directory? */
873 cmdio_write(FTP_FILEFAIL, "RNFR command failed");
876 G.rnfr_filename = xstrdup(G.ftp_arg);
877 cmdio_write_ok(FTP_RNFROK);
885 /* If we didn't get a RNFR, throw a wobbly */
886 if (G.rnfr_filename == NULL || G.ftp_arg == NULL) {
887 cmdio_write(FTP_NEEDRNFR, "RNFR required first");
891 retval = rename(G.rnfr_filename, G.ftp_arg);
892 free(G.rnfr_filename);
893 G.rnfr_filename = NULL;
896 cmdio_write(FTP_FILEFAIL, "Rename failed");
899 cmdio_write_ok(FTP_RENAMEOK);
905 handle_upload_common(0, 0);
911 handle_upload_common(1, 0);
917 handle_upload_common(0, 1);
919 #endif /* ENABLE_FEATURE_FTP_WRITE */
921 /* TODO: libbb candidate (tftp has another copy) */
922 static len_and_sockaddr *get_sock_lsa(int s)
924 len_and_sockaddr *lsa;
927 if (getsockname(s, NULL, &len) != 0)
929 lsa = xzalloc(LSA_LEN_SIZE + len);
931 getsockname(s, &lsa->u.sa, &lsa->len);
935 int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
936 int ftpd_main(int argc UNUSED_PARAM, char **argv)
940 G.local_addr = get_sock_lsa(STDIN_FILENO);
942 /* This is confusing:
943 * bb_error_msg_and_die("stdin is not a socket");
946 /* Help text says that ftpd must be used as inetd service,
947 * which is by far the most usual cause of get_sock_lsa
951 G.opts = getopt32(argv, "v" USE_FEATURE_FTP_WRITE("w"));
953 openlog(applet_name, LOG_PID, LOG_DAEMON);
954 logmode |= LOGMODE_SYSLOG;
955 if (!(G.opts & OPT_v))
956 logmode = LOGMODE_SYSLOG;
959 xchdir(argv[optind]);
963 //umask(077); - admin can set umask before starting us
965 /* Signals. We'll always take -EPIPE rather than a rude signal, thanks */
966 signal(SIGPIPE, SIG_IGN);
968 /* Set up options on the command socket (do we need these all? why?) */
969 setsockopt(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY, &const_int_1, sizeof(const_int_1));
970 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
971 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE, &const_int_1, sizeof(const_int_1));
973 cmdio_write(FTP_GREET, "Welcome");
975 #ifdef IF_WE_WANT_TO_REQUIRE_LOGIN
977 smallint user_was_specified = 0;
979 uint32_t cmdval = cmdio_get_cmd_and_arg();
981 if (cmdval == const_USER) {
982 if (G.ftp_arg == NULL || strcasecmp(G.ftp_arg, "anonymous") != 0)
983 cmdio_write(FTP_LOGINERR, "Server is anonymous only");
985 user_was_specified = 1;
986 cmdio_write(FTP_GIVEPWORD, "Please specify the password");
988 } else if (cmdval == const_PASS) {
989 if (user_was_specified)
991 cmdio_write(FTP_NEEDUSER, "Login with USER");
992 } else if (cmdval == const_QUIT) {
993 cmdio_write(FTP_GOODBYE, "Goodbye");
996 cmdio_write(FTP_LOGINERR, "Login with USER and PASS");
1000 cmdio_write_ok(FTP_LOGINOK);
1003 /* RFC-959 Section 5.1
1004 * The following commands and options MUST be supported by every
1005 * server-FTP and user-FTP, except in cases where the underlying
1006 * file system or operating system does not allow or support
1007 * a particular command.
1008 * Type: ASCII Non-print, IMAGE, LOCAL 8
1010 * Structure: File, Record*
1011 * (Record structure is REQUIRED only for hosts whose file
1012 * systems support record structure).
1014 * USER, PASS, ACCT, [bbox: ACCT not supported]
1019 * CWD, CDUP, RMD, MKD, PWD,
1025 * The argument field is a Telnet string identifying the user's account.
1026 * The command is not necessarily related to the USER command, as some
1027 * sites may require an account for login and others only for specific
1028 * access, such as storing files. In the latter case the command may
1029 * arrive at any time.
1030 * There are reply codes to differentiate these cases for the automation:
1031 * when account information is required for login, the response to
1032 * a successful PASSword command is reply code 332. On the other hand,
1033 * if account information is NOT required for login, the reply to
1034 * a successful PASSword command is 230; and if the account information
1035 * is needed for a command issued later in the dialogue, the server
1036 * should return a 332 or 532 reply depending on whether it stores
1037 * (pending receipt of the ACCounT command) or discards the command,
1042 uint32_t cmdval = cmdio_get_cmd_and_arg();
1044 if (cmdval == const_QUIT) {
1045 cmdio_write(FTP_GOODBYE, "Goodbye");
1048 if (cmdval == const_PWD)
1050 else if (cmdval == const_CWD)
1052 else if (cmdval == const_CDUP) /* cd .. */
1054 else if (cmdval == const_PASV)
1056 else if (cmdval == const_RETR)
1058 else if (cmdval == const_NOOP)
1059 cmdio_write_ok(FTP_NOOPOK);
1060 else if (cmdval == const_SYST)
1061 cmdio_write(FTP_SYSTOK, "UNIX Type: L8");
1062 else if (cmdval == const_HELP)
1064 else if (cmdval == const_LIST) /* ls -l */
1066 else if (cmdval == const_TYPE)
1068 else if (cmdval == const_PORT)
1070 else if (cmdval == const_REST)
1072 else if (cmdval == const_NLST) /* "name list", bare ls */
1074 else if (cmdval == const_STRU) {
1076 // && (G.ftp_arg[0] | 0x20) == 'f'
1077 // && G.ftp_arg[1] == '\0'
1079 cmdio_write(FTP_STRUOK, "Command ignored");
1081 // cmdio_write(FTP_BADSTRU, "Bad STRU command");
1082 } else if (cmdval == const_MODE) {
1084 // && (G.ftp_arg[0] | 0x20) == 's'
1085 // && G.ftp_arg[1] == '\0'
1087 cmdio_write(FTP_MODEOK, "Command ignored");
1089 // cmdio_write(FTP_BADMODE, "Bad MODE command");
1091 else if (cmdval == const_ALLO)
1092 cmdio_write(FTP_ALLOOK, "Command ignored");
1093 else if (cmdval == const_STAT) {
1094 if (G.ftp_arg == NULL)
1098 } else if (cmdval == const_USER) {
1099 /* FTP_LOGINERR confuses clients: */
1100 /* cmdio_write(FTP_LOGINERR, "Can't change to another user"); */
1101 cmdio_write(FTP_GIVEPWORD, "Command ignored");
1102 } else if (cmdval == const_PASS)
1103 cmdio_write(FTP_LOGINOK, "Command ignored");
1104 #if ENABLE_FEATURE_FTP_WRITE
1105 else if (G.opts & OPT_w) {
1106 if (cmdval == const_STOR)
1108 else if (cmdval == const_MKD)
1110 else if (cmdval == const_RMD)
1112 else if (cmdval == const_DELE)
1114 else if (cmdval == const_RNFR) /* "rename from" */
1116 else if (cmdval == const_RNTO) /* "rename to" */
1118 else if (cmdval == const_APPE)
1120 else if (cmdval == const_STOU) /* "store unique" */
1125 else if (cmdval == const_STOR
1126 || cmdval == const_MKD
1127 || cmdval == const_RMD
1128 || cmdval == const_DELE
1129 || cmdval == const_RNFR
1130 || cmdval == const_RNTO
1131 || cmdval == const_APPE
1132 || cmdval == const_STOU
1134 cmdio_write(FTP_NOPERM, "Permission denied");
1138 /* Which unsupported commands were seen in the wild
1139 * (doesn't necessarily mean "we must support them")
1140 * wget 1.11.4: SIZE - todo.
1141 * lftp 3.6.3: MDTM - works fine without it anyway.
1143 cmdio_write(FTP_BADCMD, "Unknown command");