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
13 * TODO: implement "421 Timeout" thingy (alarm(60) while waiting for a cmd).
18 #include <netinet/tcp.h>
32 FTP_STATFILE_OK = 213,
49 FTP_BADSENDCONN = 425,
51 FTP_BADSENDFILE = 451,
53 FTP_COMMANDNOTIMPL = 502,
63 #define mk_const4(a,b,c,d) (((a * 0x100 + b) * 0x100 + c) * 0x100 + d)
64 #define mk_const3(a,b,c) ((a * 0x100 + b) * 0x100 + c)
65 const_ALLO = mk_const4('A', 'L', 'L', 'O'),
66 const_APPE = mk_const4('A', 'P', 'P', 'E'),
67 const_CDUP = mk_const4('C', 'D', 'U', 'P'),
68 const_CWD = mk_const3('C', 'W', 'D'),
69 const_DELE = mk_const4('D', 'E', 'L', 'E'),
70 const_HELP = mk_const4('H', 'E', 'L', 'P'),
71 const_LIST = mk_const4('L', 'I', 'S', 'T'),
72 const_MKD = mk_const3('M', 'K', 'D'),
73 const_MODE = mk_const4('M', 'O', 'D', 'E'),
74 const_NLST = mk_const4('N', 'L', 'S', 'T'),
75 const_NOOP = mk_const4('N', 'O', 'O', 'P'),
76 const_PASS = mk_const4('P', 'A', 'S', 'S'),
77 const_PASV = mk_const4('P', 'A', 'S', 'V'),
78 const_PORT = mk_const4('P', 'O', 'R', 'T'),
79 const_PWD = mk_const3('P', 'W', 'D'),
80 const_QUIT = mk_const4('Q', 'U', 'I', 'T'),
81 const_REST = mk_const4('R', 'E', 'S', 'T'),
82 const_RETR = mk_const4('R', 'E', 'T', 'R'),
83 const_RMD = mk_const3('R', 'M', 'D'),
84 const_RNFR = mk_const4('R', 'N', 'F', 'R'),
85 const_RNTO = mk_const4('R', 'N', 'T', 'O'),
86 const_STAT = mk_const4('S', 'T', 'A', 'T'),
87 const_STOR = mk_const4('S', 'T', 'O', 'R'),
88 const_STOU = mk_const4('S', 'T', 'O', 'U'),
89 const_STRU = mk_const4('S', 'T', 'R', 'U'),
90 const_SYST = mk_const4('S', 'Y', 'S', 'T'),
91 const_TYPE = mk_const4('T', 'Y', 'P', 'E'),
92 const_USER = mk_const4('U', 'S', 'E', 'R'),
96 char *p_control_line_buf;
97 len_and_sockaddr *local_addr;
98 len_and_sockaddr *port_addr;
104 #if ENABLE_FEATURE_FTP_WRITE
109 #define G (*(struct globals*)&bb_common_bufsiz1)
110 #define INIT_G() do { } while (0)
113 replace_text(const char *str, const char from, const char *to)
115 size_t retlen, remainlen, chunklen, tolen;
120 remainlen = strlen(str);
123 /* Simply alloc strlen(str)*strlen(to). "to" is max 2 so it's ok */
124 ret = xmalloc(remainlen * tolen + 1);
128 found = strchr(remain, from);
130 chunklen = found - remain;
132 /* Copy chunk which doesn't contain 'from' to ret */
133 memcpy(&ret[retlen], remain, chunklen);
136 /* Now copy 'to' instead of 'from' */
137 memcpy(&ret[retlen], to, tolen);
143 * The last chunk. We are already sure that we have enough space
144 * so we can use strcpy.
146 strcpy(&ret[retlen], remain);
154 replace_char(char *str, char from, char to)
156 while ((str = strchr(str, from)) != NULL)
161 ftp_write_str_common(unsigned status, const char *str, char sep)
163 char *escaped_str, *response;
166 /* FTP allegedly uses telnet protocol for command link.
167 * In telnet, 0xff is an escape char, and needs to be escaped: */
168 escaped_str = replace_text(str, '\xff', "\xff\xff");
170 response = xasprintf("%u%c%s\r", status, sep, escaped_str);
173 /* ?! does FTP send embedded LFs as NULs? wow */
174 len = strlen(response);
175 replace_char(response, '\n', '\0');
177 response[len++] = '\n'; /* tack on trailing '\n' */
178 xwrite(STDIN_FILENO, response, len);
183 cmdio_write(int status, const char *p_text)
185 ftp_write_str_common(status, p_text, ' ');
189 cmdio_write_ok(int status)
191 ftp_write_str_common(status, "Operation successful", ' ');
195 cmdio_write_hyphen(int status, const char *p_text)
197 ftp_write_str_common(status, p_text, '-');
201 cmdio_write_raw(const char *p_text)
203 xwrite_str(STDIN_FILENO, p_text);
209 char *cwd, *promoted_cwd, *response;
211 cwd = xrealloc_getcwd_or_warn(NULL);
215 /* We have to promote each " to "" */
216 promoted_cwd = replace_text(cwd, '\"', "\"\"");
218 response = xasprintf("\"%s\"", promoted_cwd);
220 cmdio_write(FTP_PWDOK, response);
227 if (!G.ftp_arg || chdir(G.ftp_arg) != 0) {
228 cmdio_write(FTP_FILEFAIL, "Can't change directory");
231 cmdio_write_ok(FTP_CWDOK);
237 G.ftp_arg = (char*)"..";
245 && ( ((G.ftp_arg[0] | 0x20) == 'i' && G.ftp_arg[1] == '\0')
246 || !strcasecmp(G.ftp_arg, "L8")
247 || !strcasecmp(G.ftp_arg, "L 8")
250 cmdio_write_ok(FTP_TYPEOK);
252 cmdio_write(FTP_BADCMD, "Unrecognised TYPE command");
259 cmdio_write_hyphen(FTP_HELP, "Recognized commands:");
260 cmdio_write_raw(" ALLO CDUP CWD HELP LIST\r\n"
261 " MODE NLST NOOP PASS PASV PORT PWD QUIT\r\n"
262 " REST RETR STAT STRU SYST TYPE USER\r\n"
263 #if ENABLE_FEATURE_FTP_WRITE
264 " APPE DELE MKD RMD RNFR RNTO STOR STOU\r\n"
267 cmdio_write(FTP_HELP, "Help OK");
271 init_data_sock_params(int sock_fd)
273 struct linger linger;
277 memset(&linger, 0, sizeof(linger));
279 linger.l_linger = 32767;
281 setsockopt(sock_fd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
282 setsockopt(sock_fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
286 ftpdataio_get_pasv_fd(void)
290 remote_fd = accept(G.pasv_listen_fd, NULL, 0);
293 cmdio_write(FTP_BADSENDCONN, "Can't establish connection");
297 init_data_sock_params(remote_fd);
302 ftpdataio_get_port_fd(void)
306 /* Do we want to die or print error to client? */
307 remote_fd = xconnect_stream(G.port_addr);
309 init_data_sock_params(remote_fd);
314 ftpdataio_dispose_transfer_fd(void)
316 /* This close() blocks because we set SO_LINGER */
317 if (G.data_fd > STDOUT_FILENO) {
318 if (close(G.data_fd) < 0) {
319 /* Do it again without blocking. */
320 struct linger linger;
322 memset(&linger, 0, sizeof(linger));
323 setsockopt(G.data_fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
333 return (G.port_addr != NULL);
339 return (G.pasv_listen_fd > STDOUT_FILENO);
343 get_remote_transfer_fd(const char *p_status_msg)
348 remote_fd = ftpdataio_get_pasv_fd();
350 remote_fd = ftpdataio_get_port_fd();
355 cmdio_write(FTP_DATACONN, p_status_msg);
360 data_transfer_checks_ok(void)
362 if (!pasv_active() && !port_active()) {
363 cmdio_write(FTP_BADSENDCONN, "Use PORT or PASV first");
371 port_pasv_cleanup(void)
375 if (G.pasv_listen_fd > STDOUT_FILENO)
376 close(G.pasv_listen_fd);
377 G.pasv_listen_fd = -1;
383 int bind_retries = 10;
385 enum { min_port = 1024, max_port = 65535 };
386 char *addr, *response;
390 G.pasv_listen_fd = xsocket(G.local_addr->u.sa.sa_family, SOCK_STREAM, 0);
391 setsockopt_reuseaddr(G.pasv_listen_fd);
393 /* TODO bind() with port == 0 and then call getsockname */
394 while (--bind_retries) {
395 port = rand() % max_port;
396 if (port < min_port) {
400 set_nport(G.local_addr, htons(port));
401 /* We don't want to use xbind, it'll die if port is in use */
402 if (bind(G.pasv_listen_fd, &G.local_addr->u.sa, G.local_addr->len) != 0) {
403 /* do we want check if errno == EADDRINUSE ? */
406 xlisten(G.pasv_listen_fd, 1);
411 bb_error_msg_and_die("can't create pasv socket");
413 addr = xmalloc_sockaddr2dotted_noport(&G.local_addr->u.sa);
414 replace_char(addr, '.', ',');
416 response = xasprintf("Entering Passive Mode (%s,%u,%u)",
417 addr, (int)(port >> 8), (int)(port & 255));
420 cmdio_write(FTP_PASVOK, response);
428 char *raw, *port_part;
429 len_and_sockaddr *lsa = NULL;
436 * xatou16 will accept wrong input,
437 * xatou16 will exit instead of generating error to peer
440 port_part = strrchr(raw, ',');
441 if (port_part == NULL)
443 port = xatou16(&port_part[1]);
446 port_part = strrchr(raw, ',');
447 if (port_part == NULL)
449 port |= xatou16(&port_part[1]) << 8;
452 replace_char(raw, ',', '.');
453 lsa = xdotted2sockaddr(raw, port);
457 cmdio_write(FTP_BADCMD, "Illegal PORT command");
462 cmdio_write_ok(FTP_PORTOK);
468 /* When ftp_arg == NULL simply restart from beginning */
469 G.restart_pos = G.ftp_arg ? xatoi_u(G.ftp_arg) : 0;
470 cmdio_write_ok(FTP_RESTOK);
477 int trans_ret, retval;
480 off_t offset = G.restart_pos;
485 if (!data_transfer_checks_ok())
488 /* O_NONBLOCK is useful if file happens to be a device node */
489 opened_file = G.ftp_arg ? open(G.ftp_arg, O_RDONLY | O_NONBLOCK) : -1;
490 if (opened_file < 0) {
491 cmdio_write(FTP_FILEFAIL, "Can't open file");
495 retval = fstat(opened_file, &statbuf);
496 if (retval < 0 || !S_ISREG(statbuf.st_mode)) {
497 /* Note - pretend open failed */
498 cmdio_write(FTP_FILEFAIL, "Can't open file");
502 /* Now deactive O_NONBLOCK, otherwise we have a problem on DMAPI filesystems
505 ndelay_off(opened_file);
507 /* Set the download offset (from REST) if any */
509 xlseek(opened_file, offset, SEEK_SET);
511 response = xasprintf(
512 "Opening BINARY mode data connection for %s (%"OFF_FMT"u bytes)",
513 G.ftp_arg, statbuf.st_size);
514 remote_fd = get_remote_transfer_fd(response);
517 goto port_pasv_cleanup_out;
519 trans_ret = bb_copyfd_eof(opened_file, remote_fd);
520 ftpdataio_dispose_transfer_fd();
522 cmdio_write(FTP_BADSENDFILE, "Error sending local file");
524 cmdio_write_ok(FTP_TRANSFEROK);
526 port_pasv_cleanup_out:
534 statbuf_getperms(const struct stat *statbuf)
537 enum { r = 'r', w = 'w', x = 'x', s = 's', S = 'S' };
540 memset(perms, '-', 10);
543 switch (statbuf->st_mode & S_IFMT) {
544 case S_IFREG: perms[0] = '-'; break;
545 case S_IFDIR: perms[0] = 'd'; break;
546 case S_IFLNK: perms[0] = 'l'; break;
547 case S_IFIFO: perms[0] = 'p'; break;
548 case S_IFSOCK: perms[0] = s; break;
549 case S_IFCHR: perms[0] = 'c'; break;
550 case S_IFBLK: perms[0] = 'b'; break;
553 if (statbuf->st_mode & S_IRUSR) perms[1] = r;
554 if (statbuf->st_mode & S_IWUSR) perms[2] = w;
555 if (statbuf->st_mode & S_IXUSR) perms[3] = x;
556 if (statbuf->st_mode & S_IRGRP) perms[4] = r;
557 if (statbuf->st_mode & S_IWGRP) perms[5] = w;
558 if (statbuf->st_mode & S_IXGRP) perms[6] = x;
559 if (statbuf->st_mode & S_IROTH) perms[7] = r;
560 if (statbuf->st_mode & S_IWOTH) perms[8] = w;
561 if (statbuf->st_mode & S_IXOTH) perms[9] = x;
562 if (statbuf->st_mode & S_ISUID) perms[3] = (perms[3] == x) ? s : S;
563 if (statbuf->st_mode & S_ISGID) perms[6] = (perms[6] == x) ? s : S;
564 if (statbuf->st_mode & S_ISVTX) perms[9] = (perms[9] == x) ? 't' : 'T';
572 write_filestats(int fd, const char *filename,
573 const struct stat *statbuf)
576 char *stats, *lnkname = NULL, *perms;
581 const char *format = "%b %d %H:%M";
583 name = bb_get_last_path_component_nostrip(filename);
585 if (statbuf != NULL) {
586 size = statbuf->st_size;
588 if (S_ISLNK(statbuf->st_mode))
589 /* Damn symlink... */
590 lnkname = xmalloc_readlink(filename);
592 tm = gmtime(&statbuf->st_mtime);
593 retval = strftime(timestr, sizeof(timestr), format, tm);
595 bb_error_msg_and_die("strftime");
597 timestr[sizeof(timestr) - 1] = '\0';
599 perms = statbuf_getperms(statbuf);
601 stats = xasprintf("%s %u\tftp ftp %"OFF_FMT"u\t%s %s",
602 perms, (int) statbuf->st_nlink,
603 size, timestr, name);
607 stats = xstrdup(name);
609 xwrite_str(fd, stats);
611 if (lnkname != NULL) {
612 xwrite_str(fd, " -> ");
613 xwrite_str(fd, lnkname);
616 xwrite_str(fd, "\r\n");
620 write_dirstats(int fd, const char *dname, int details)
623 struct dirent *dirent;
627 dir = xopendir(dname);
630 dirent = readdir(dir);
634 /* Ignore . and .. */
635 if (dirent->d_name[0] == '.') {
636 if (dirent->d_name[1] == '\0'
637 || (dirent->d_name[1] == '.' && dirent->d_name[2] == '\0')
644 filename = xasprintf("%s/%s", dname, dirent->d_name);
645 if (lstat(filename, &statbuf) != 0) {
650 filename = xstrdup(dirent->d_name);
652 write_filestats(fd, filename, details ? &statbuf : NULL);
660 handle_dir_common(int full_details, int stat_cmd)
665 if (!stat_cmd && !data_transfer_checks_ok())
670 cmdio_write_hyphen(FTP_STATFILE_OK, "Status follows:");
672 fd = get_remote_transfer_fd("Here comes the directory listing");
678 if (lstat(G.ftp_arg, &statbuf) != 0) {
679 /* Dir doesn't exist => return ok to client */
682 if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode))
683 write_filestats(fd, G.ftp_arg, &statbuf);
684 else if (S_ISDIR(statbuf.st_mode))
685 write_dirstats(fd, G.ftp_arg, full_details);
687 write_dirstats(fd, ".", full_details);
690 /* Well, if we can't open directory/file it doesn't matter */
692 ftpdataio_dispose_transfer_fd();
694 cmdio_write_ok(FTP_TRANSFEROK);
696 cmdio_write_ok(FTP_STATFILE_OK);
702 handle_dir_common(1, 0);
708 handle_dir_common(0, 0);
712 handle_stat_file(void)
714 handle_dir_common(1, 1);
720 cmdio_write_hyphen(FTP_STATOK, "FTP server status:");
721 cmdio_write_raw(" TYPE: BINARY\r\n");
722 cmdio_write_ok(FTP_STATOK);
725 #if ENABLE_FEATURE_FTP_WRITE
729 if (!G.ftp_arg || mkdir(G.ftp_arg, 0777) != 0) {
730 cmdio_write(FTP_FILEFAIL, "Create directory operation failed");
733 cmdio_write_ok(FTP_MKDIROK);
739 if (!G.ftp_arg || rmdir(G.ftp_arg) != 0) {
740 cmdio_write(FTP_FILEFAIL, "Deletion failed");
743 cmdio_write_ok(FTP_RMDIROK);
749 if (!G.ftp_arg || unlink(G.ftp_arg) != 0) {
750 cmdio_write(FTP_FILEFAIL, "Deletion failed");
753 cmdio_write_ok(FTP_DELEOK);
761 /* Clear old value */
762 free(G.rnfr_filename);
763 G.rnfr_filename = NULL;
766 || stat(G.ftp_arg, &statbuf) != 0
767 /* || it isn't a regular file or a directory? */
769 cmdio_write(FTP_FILEFAIL, "RNFR command failed");
772 G.rnfr_filename = xstrdup(G.ftp_arg);
773 cmdio_write_ok(FTP_RNFROK);
781 /* If we didn't get a RNFR, throw a wobbly */
782 if (G.rnfr_filename == NULL || G.ftp_arg == NULL) {
783 cmdio_write(FTP_NEEDRNFR, "RNFR required first");
787 retval = rename(G.rnfr_filename, G.ftp_arg);
788 free(G.rnfr_filename);
789 G.rnfr_filename = NULL;
792 cmdio_write(FTP_FILEFAIL, "Rename failed");
795 cmdio_write_ok(FTP_RENAMEOK);
799 handle_upload_common(int is_append, int is_unique)
801 char *tempname = NULL;
807 offset = G.restart_pos;
810 if (!data_transfer_checks_ok())
815 tempname = xstrdup("FILE: uniq.XXXXXX");
816 local_file_fd = mkstemp(tempname + 6);
817 } else if (G.ftp_arg) {
818 int flags = O_WRONLY | O_CREAT | O_TRUNC;
820 flags = O_WRONLY | O_CREAT | O_APPEND;
822 flags = O_WRONLY | O_CREAT;
823 local_file_fd = open(G.ftp_arg, flags, 0666);
825 if (local_file_fd < 0) {
826 cmdio_write(FTP_UPLOADFAIL, "Can't create file");
830 /* TODO: paranoia: fstat it, refuse to do anything if it's not a regular file */
833 xlseek(local_file_fd, offset, SEEK_SET);
835 remote_fd = get_remote_transfer_fd(tempname ? tempname : "Ok to send data");
841 trans_ret = bb_copyfd_eof(remote_fd, local_file_fd);
842 ftpdataio_dispose_transfer_fd();
845 cmdio_write(FTP_BADSENDFILE, "Failure writing to local file");
847 cmdio_write_ok(FTP_TRANSFEROK);
851 close(local_file_fd);
857 handle_upload_common(0, 0);
864 handle_upload_common(1, 0);
871 handle_upload_common(0, 1);
873 #endif /* ENABLE_FEATURE_FTP_WRITE */
876 cmdio_get_cmd_and_arg(void)
883 len = 8 * 1024; /* Paranoia. Peer may send 1 gigabyte long cmd... */
884 G.ftp_cmp = cmd = xmalloc_reads(STDIN_FILENO, NULL, &len);
888 len = strlen(cmd) - 1;
889 while (len >= 0 && cmd[len] == '\r') {
894 G.ftp_arg = strchr(cmd, ' ');
895 if (G.ftp_arg != NULL) {
901 cmdval = (cmdval << 8) + ((unsigned char)*cmd++ & (unsigned char)~0x20);
906 int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
907 int ftpd_main(int argc UNUSED_PARAM, char **argv)
911 G.local_addr = get_sock_lsa(STDIN_FILENO);
913 /* This is confusing:
914 * bb_error_msg_and_die("stdin is not a socket");
917 /* Help text says that ftpd must be used as inetd service,
918 * which is by far the most usual cause of get_sock_lsa
922 G.opts = getopt32(argv, "v" USE_FEATURE_FTP_WRITE("w"));
924 openlog(applet_name, LOG_PID, LOG_DAEMON);
925 logmode |= LOGMODE_SYSLOG;
926 if (!(G.opts & OPT_v))
927 logmode = LOGMODE_SYSLOG;
930 xchdir(argv[optind]);
934 //umask(077); - admin can set umask before starting us
936 /* Signals. We'll always take -EPIPE rather than a rude signal, thanks */
937 signal(SIGPIPE, SIG_IGN);
939 /* Set up options on the command socket (do we need these all? why?) */
940 setsockopt(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY, &const_int_1, sizeof(const_int_1));
941 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
942 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE, &const_int_1, sizeof(const_int_1));
944 cmdio_write(FTP_GREET, "Welcome");
946 #ifdef IF_WE_WANT_TO_REQUIRE_LOGIN
948 smallint user_was_specified = 0;
950 uint32_t cmdval = cmdio_get_cmd_and_arg();
952 if (cmdval == const_USER) {
953 if (G.ftp_arg == NULL || strcasecmp(G.ftp_arg, "anonymous") != 0)
954 cmdio_write(FTP_LOGINERR, "Server is anonymous only");
956 user_was_specified = 1;
957 cmdio_write(FTP_GIVEPWORD, "Please specify the password");
959 } else if (cmdval == const_PASS) {
960 if (user_was_specified)
962 cmdio_write(FTP_NEEDUSER, "Login with USER");
963 } else if (cmdval == const_QUIT) {
964 cmdio_write(FTP_GOODBYE, "Goodbye");
967 cmdio_write(FTP_LOGINERR, "Login with USER and PASS");
971 cmdio_write_ok(FTP_LOGINOK);
974 /* RFC-959 Section 5.1
975 * The following commands and options MUST be supported by every
976 * server-FTP and user-FTP, except in cases where the underlying
977 * file system or operating system does not allow or support
978 * a particular command.
979 * Type: ASCII Non-print, IMAGE, LOCAL 8
981 * Structure: File, Record*
982 * (Record structure is REQUIRED only for hosts whose file
983 * systems support record structure).
985 * USER, PASS, ACCT, [bbox: ACCT not supported]
990 * CWD, CDUP, RMD, MKD, PWD,
996 * The argument field is a Telnet string identifying the user's account.
997 * The command is not necessarily related to the USER command, as some
998 * sites may require an account for login and others only for specific
999 * access, such as storing files. In the latter case the command may
1000 * arrive at any time.
1001 * There are reply codes to differentiate these cases for the automation:
1002 * when account information is required for login, the response to
1003 * a successful PASSword command is reply code 332. On the other hand,
1004 * if account information is NOT required for login, the reply to
1005 * a successful PASSword command is 230; and if the account information
1006 * is needed for a command issued later in the dialogue, the server
1007 * should return a 332 or 532 reply depending on whether it stores
1008 * (pending receipt of the ACCounT command) or discards the command,
1013 uint32_t cmdval = cmdio_get_cmd_and_arg();
1015 if (cmdval == const_QUIT) {
1016 cmdio_write(FTP_GOODBYE, "Goodbye");
1019 if (cmdval == const_PWD)
1021 else if (cmdval == const_CWD)
1023 else if (cmdval == const_CDUP) /* cd .. */
1025 else if (cmdval == const_PASV)
1027 else if (cmdval == const_RETR)
1029 else if (cmdval == const_NOOP)
1030 cmdio_write_ok(FTP_NOOPOK);
1031 else if (cmdval == const_SYST)
1032 cmdio_write(FTP_SYSTOK, "UNIX Type: L8");
1033 else if (cmdval == const_HELP)
1035 else if (cmdval == const_LIST) /* ls -l */
1037 else if (cmdval == const_TYPE)
1039 else if (cmdval == const_PORT)
1041 else if (cmdval == const_REST)
1043 else if (cmdval == const_NLST) /* "name list", bare ls */
1045 else if (cmdval == const_STRU) {
1047 // && (G.ftp_arg[0] | 0x20) == 'f'
1048 // && G.ftp_arg[1] == '\0'
1050 cmdio_write(FTP_STRUOK, "Command ignored");
1052 // cmdio_write(FTP_BADSTRU, "Bad STRU command");
1053 } else if (cmdval == const_MODE) {
1055 // && (G.ftp_arg[0] | 0x20) == 's'
1056 // && G.ftp_arg[1] == '\0'
1058 cmdio_write(FTP_MODEOK, "Command ignored");
1060 // cmdio_write(FTP_BADMODE, "Bad MODE command");
1062 else if (cmdval == const_ALLO)
1063 cmdio_write(FTP_ALLOOK, "Command ignored");
1064 else if (cmdval == const_STAT) {
1065 if (G.ftp_arg == NULL)
1069 } else if (cmdval == const_USER) {
1070 /* FTP_LOGINERR confuses clients: */
1071 /* cmdio_write(FTP_LOGINERR, "Can't change to another user"); */
1072 cmdio_write(FTP_GIVEPWORD, "Command ignored");
1073 } else if (cmdval == const_PASS)
1074 cmdio_write(FTP_LOGINOK, "Command ignored");
1075 #if ENABLE_FEATURE_FTP_WRITE
1076 else if (G.opts & OPT_w) {
1077 if (cmdval == const_STOR)
1079 else if (cmdval == const_MKD)
1081 else if (cmdval == const_RMD)
1083 else if (cmdval == const_DELE)
1085 else if (cmdval == const_RNFR) /* "rename from" */
1087 else if (cmdval == const_RNTO) /* "rename to" */
1089 else if (cmdval == const_APPE)
1091 else if (cmdval == const_STOU) /* "store unique" */
1096 else if (cmdval == const_STOR
1097 || cmdval == const_MKD
1098 || cmdval == const_RMD
1099 || cmdval == const_DELE
1100 || cmdval == const_RNFR
1101 || cmdval == const_RNTO
1102 || cmdval == const_APPE
1103 || cmdval == const_STOU
1105 cmdio_write(FTP_NOPERM, "Permission denied");
1109 /* Which unsupported commands were seen in the wild?
1110 * (doesn't necessarily mean "we must support them")
1111 * wget 1.11.4: SIZE - todo.
1112 * lftp 3.6.3: MDTM - works fine without it anyway.
1113 * IPv6-style PASV: "EPSV 2"
1115 cmdio_write(FTP_BADCMD, "Unknown command");