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)
111 replace_text(const char *str, const char from, const char *to)
113 size_t retlen, remainlen, chunklen, tolen;
118 remainlen = strlen(str);
121 /* Simply alloc strlen(str)*strlen(to). "to" is max 2 so it's ok */
122 ret = xmalloc(remainlen * tolen + 1);
126 found = strchr(remain, from);
128 chunklen = found - remain;
130 /* Copy chunk which doesn't contain 'from' to ret */
131 memcpy(&ret[retlen], remain, chunklen);
134 /* Now copy 'to' instead of 'from' */
135 memcpy(&ret[retlen], to, tolen);
141 * The last chunk. We are already sure that we have enough space
142 * so we can use strcpy.
144 strcpy(&ret[retlen], remain);
152 replace_char(char *str, char from, char to)
154 while ((str = strchr(str, from)) != NULL)
159 ftp_write_str_common(unsigned int status, const char *str, char sep)
161 char *escaped_str, *response;
164 escaped_str = replace_text(str, '\377', "\377\377");
166 response = xasprintf("%u%c%s\r\n", status, sep, escaped_str);
169 len = strlen(response);
170 replace_char(response, '\n', '\0');
172 /* Change trailing '\0' back to '\n' */
173 response[len - 1] = '\n';
174 xwrite(STDIN_FILENO, response, len);
178 cmdio_write(int status, const char *p_text)
180 ftp_write_str_common(status, p_text, ' ');
184 cmdio_write_ok(int status)
186 ftp_write_str_common(status, "Operation successful", ' ');
190 cmdio_write_hyphen(int status, const char *p_text)
192 ftp_write_str_common(status, p_text, '-');
196 cmdio_write_raw(const char *p_text)
198 xwrite_str(STDIN_FILENO, p_text);
202 cmdio_get_cmd_and_arg(void)
209 len = 8 * 1024; /* Paranoia. Peer may send 1 gigabyte long cmd... */
210 G.ftp_cmp = cmd = xmalloc_reads(STDIN_FILENO, NULL, &len);
214 len = strlen(cmd) - 1;
215 while (len >= 0 && cmd[len] == '\r') {
220 G.ftp_arg = strchr(cmd, ' ');
221 if (G.ftp_arg != NULL) {
222 *(char *)G.ftp_arg = '\0';
227 cmdval = (cmdval << 8) + ((unsigned char)*cmd++ & (unsigned char)~0x20);
233 init_data_sock_params(int sock_fd)
235 struct linger linger;
239 memset(&linger, 0, sizeof(linger));
241 linger.l_linger = 32767;
243 setsockopt(sock_fd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
244 setsockopt(sock_fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
248 ftpdataio_get_pasv_fd(void)
252 remote_fd = accept(G.pasv_listen_fd, NULL, 0);
255 cmdio_write(FTP_BADSENDCONN, "Can't establish connection");
259 init_data_sock_params(remote_fd);
264 ftpdataio_get_port_fd(void)
268 /* Do we want die or print error to client? */
269 remote_fd = xconnect_stream(G.port_addr);
271 init_data_sock_params(remote_fd);
276 ftpdataio_dispose_transfer_fd(void)
278 /* This close() blocks because we set SO_LINGER */
279 if (G.data_fd > STDOUT_FILENO) {
280 if (close(G.data_fd) < 0) {
281 /* Do it again without blocking. */
282 struct linger linger;
284 memset(&linger, 0, sizeof(linger));
285 setsockopt(G.data_fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
295 return (G.port_addr != NULL) ? 1: 0;
301 return (G.pasv_listen_fd != -1) ? 1 : 0;
305 get_remote_transfer_fd(const char *p_status_msg)
310 remote_fd = ftpdataio_get_pasv_fd();
312 remote_fd = ftpdataio_get_port_fd();
317 cmdio_write(FTP_DATACONN, p_status_msg);
324 char *cwd, *promoted_cwd, *response;
326 cwd = xrealloc_getcwd_or_warn(NULL);
330 /* We have to promote each " to "" */
331 promoted_cwd = replace_text(cwd, '\"', "\"\"");
333 response = xasprintf("\"%s\"", promoted_cwd);
335 cmdio_write(FTP_PWDOK, response);
342 if (!G.ftp_arg || chdir(G.ftp_arg) != 0) {
343 cmdio_write(FTP_FILEFAIL, "Can't change directory");
346 cmdio_write_ok(FTP_CWDOK);
357 data_transfer_checks_ok(void)
359 if (!pasv_active() && !port_active()) {
360 cmdio_write(FTP_BADSENDCONN, "Use PORT or PASV first");
377 if (G.pasv_listen_fd > STDOUT_FILENO)
378 close(G.pasv_listen_fd);
379 G.pasv_listen_fd = -1;
385 int bind_retries = 10;
387 enum { min_port = 1024, max_port = 65535 };
388 char *addr, *wire_addr, *response;
392 G.pasv_listen_fd = xsocket(G.local_addr->u.sa.sa_family, SOCK_STREAM, 0);
393 setsockopt_reuseaddr(G.pasv_listen_fd);
395 /* TODO bind() with port == 0 and then call getsockname */
396 while (--bind_retries) {
397 port = rand() % max_port;
398 if (port < min_port) {
402 set_nport(G.local_addr, htons(port));
403 /* We don't want to use xbind, it'll die if port is in use */
404 if (bind(G.pasv_listen_fd, &G.local_addr->u.sa, G.local_addr->len) != 0) {
405 /* do we want check if errno == EADDRINUSE ? */
408 xlisten(G.pasv_listen_fd, 1);
413 bb_error_msg_and_die("can't create pasv socket");
415 addr = xmalloc_sockaddr2dotted_noport(&G.local_addr->u.sa);
416 wire_addr = replace_text(addr, '.', ",");
419 response = xasprintf("Entering Passive Mode (%s,%u,%u)",
420 wire_addr, (int)(port >> 8), (int)(port & 255));
422 cmdio_write(FTP_PASVOK, response);
431 char *raw = NULL, *port_part;
432 len_and_sockaddr *lsa = NULL;
437 if (G.ftp_arg == NULL)
440 raw = replace_text(G.ftp_arg, ',', ".");
442 port_part = strrchr(raw, '.');
443 if (port_part == NULL)
446 port = xatou16(&port_part[1]);
449 port_part = strrchr(raw, '.');
450 if (port_part == NULL)
453 port |= xatou16(&port_part[1]) << 8;
456 lsa = xdotted2sockaddr(raw, port);
462 cmdio_write(FTP_BADCMD, "Illegal PORT command");
467 cmdio_write_ok(FTP_PORTOK);
473 /* When ftp_arg == NULL simply restart from beginning */
474 G.restart_pos = G.ftp_arg ? xatoi_u(G.ftp_arg) : 0;
475 cmdio_write_ok(FTP_RESTOK);
482 int trans_ret, retval;
485 off_t offset = G.restart_pos;
490 if (!data_transfer_checks_ok())
493 /* O_NONBLOCK is useful if file happens to be a device node */
494 opened_file = G.ftp_arg ? open(G.ftp_arg, O_RDONLY | O_NONBLOCK) : -1;
495 if (opened_file < 0) {
496 cmdio_write(FTP_FILEFAIL, "Can't open file");
500 retval = fstat(opened_file, &statbuf);
501 if (retval < 0 || !S_ISREG(statbuf.st_mode)) {
502 /* Note - pretend open failed */
503 cmdio_write(FTP_FILEFAIL, "Can't open file");
507 /* Now deactive O_NONBLOCK, otherwise we have a problem on DMAPI filesystems
510 ndelay_off(opened_file);
512 /* Set the download offset (from REST) if any */
514 xlseek(opened_file, offset, SEEK_SET);
516 response = xasprintf(
517 "Opening BINARY mode data connection for %s (%"OFF_FMT"u bytes)",
518 G.ftp_arg, statbuf.st_size);
519 remote_fd = get_remote_transfer_fd(response);
522 goto port_pasv_cleanup_out;
524 trans_ret = bb_copyfd_eof(opened_file, remote_fd);
525 ftpdataio_dispose_transfer_fd();
527 cmdio_write(FTP_BADSENDFILE, "Error sending local file");
529 cmdio_write_ok(FTP_TRANSFEROK);
531 port_pasv_cleanup_out:
539 statbuf_getperms(const struct stat *statbuf)
542 enum { r = 'r', w = 'w', x = 'x', s = 's', S = 'S' };
545 memset(perms, '-', 10);
548 switch (statbuf->st_mode & S_IFMT) {
549 case S_IFREG: perms[0] = '-'; break;
550 case S_IFDIR: perms[0] = 'd'; break;
551 case S_IFLNK: perms[0] = 'l'; break;
552 case S_IFIFO: perms[0] = 'p'; break;
553 case S_IFSOCK: perms[0] = s; break;
554 case S_IFCHR: perms[0] = 'c'; break;
555 case S_IFBLK: perms[0] = 'b'; break;
558 if (statbuf->st_mode & S_IRUSR) perms[1] = r;
559 if (statbuf->st_mode & S_IWUSR) perms[2] = w;
560 if (statbuf->st_mode & S_IXUSR) perms[3] = x;
561 if (statbuf->st_mode & S_IRGRP) perms[4] = r;
562 if (statbuf->st_mode & S_IWGRP) perms[5] = w;
563 if (statbuf->st_mode & S_IXGRP) perms[6] = x;
564 if (statbuf->st_mode & S_IROTH) perms[7] = r;
565 if (statbuf->st_mode & S_IWOTH) perms[8] = w;
566 if (statbuf->st_mode & S_IXOTH) perms[9] = x;
567 if (statbuf->st_mode & S_ISUID) perms[3] = (perms[3] == x) ? s : S;
568 if (statbuf->st_mode & S_ISGID) perms[6] = (perms[6] == x) ? s : S;
569 if (statbuf->st_mode & S_ISVTX) perms[9] = (perms[9] == x) ? 't' : 'T';
577 write_filestats(int fd, const char *filename,
578 const struct stat *statbuf)
581 char *stats, *lnkname = NULL, *perms;
586 const char *format = "%b %d %H:%M";
588 name = bb_get_last_path_component_nostrip(filename);
590 if (statbuf != NULL) {
591 size = statbuf->st_size;
593 if (S_ISLNK(statbuf->st_mode))
594 /* Damn symlink... */
595 lnkname = xmalloc_readlink(filename);
597 tm = gmtime(&statbuf->st_mtime);
598 retval = strftime(timestr, sizeof(timestr), format, tm);
600 bb_error_msg_and_die("strftime");
602 timestr[sizeof(timestr) - 1] = '\0';
604 perms = statbuf_getperms(statbuf);
606 stats = xasprintf("%s %u\tftp ftp %"OFF_FMT"u\t%s %s",
607 perms, (int) statbuf->st_nlink,
608 size, timestr, name);
612 stats = xstrdup(name);
614 xwrite_str(fd, stats);
616 if (lnkname != NULL) {
617 xwrite_str(fd, " -> ");
618 xwrite_str(fd, lnkname);
621 xwrite_str(fd, "\r\n");
625 write_dirstats(int fd, const char *dname, int details)
628 struct dirent *dirent;
632 dir = xopendir(dname);
635 dirent = readdir(dir);
639 /* Ignore . and .. */
640 if (dirent->d_name[0] == '.') {
641 if (dirent->d_name[1] == '\0'
642 || (dirent->d_name[1] == '.' && dirent->d_name[2] == '\0')
649 filename = xasprintf("%s/%s", dname, dirent->d_name);
650 if (lstat(filename, &statbuf) != 0) {
655 filename = xstrdup(dirent->d_name);
657 write_filestats(fd, filename, details ? &statbuf : NULL);
665 handle_dir_common(int full_details, int stat_cmd)
670 if (!stat_cmd && !data_transfer_checks_ok())
675 cmdio_write_hyphen(FTP_STATFILE_OK, "Status follows:");
677 fd = get_remote_transfer_fd("Here comes the directory listing");
683 if (lstat(G.ftp_arg, &statbuf) != 0) {
684 /* Dir doesn't exist => return ok to client */
687 if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode))
688 write_filestats(fd, G.ftp_arg, &statbuf);
689 else if (S_ISDIR(statbuf.st_mode))
690 write_dirstats(fd, G.ftp_arg, full_details);
692 write_dirstats(fd, ".", full_details);
695 /* Well, if we can't open directory/file it doesn't matter */
697 ftpdataio_dispose_transfer_fd();
700 cmdio_write_ok(FTP_TRANSFEROK);
702 cmdio_write_ok(FTP_STATFILE_OK);
708 handle_dir_common(1, 0);
714 handle_dir_common(0, 0);
718 handle_stat_file(void)
720 handle_dir_common(1, 1);
726 cmdio_write_hyphen(FTP_STATOK, "FTP server status:");
727 cmdio_write_raw(" TYPE: BINARY\r\n");
728 cmdio_write_ok(FTP_STATOK);
735 && ( ((G.ftp_arg[0] | 0x20) == 'i' && G.ftp_arg[1] == '\0')
736 || !strcasecmp(G.ftp_arg, "L8")
737 || !strcasecmp(G.ftp_arg, "L 8")
740 cmdio_write_ok(FTP_TYPEOK);
742 cmdio_write(FTP_BADCMD, "Unrecognised TYPE command");
749 cmdio_write_hyphen(FTP_HELP, "Recognized commands:");
750 cmdio_write_raw(" ALLO CDUP CWD HELP LIST\r\n"
751 " MODE NLST NOOP PASS PASV PORT PWD QUIT\r\n"
752 " REST RETR STAT STRU SYST TYPE USER\r\n"
753 #if ENABLE_FEATURE_FTP_WRITE
754 " APPE DELE MKD RMD RNFR RNTO STOR STOU\r\n"
757 cmdio_write(FTP_HELP, "Help OK");
760 #if ENABLE_FEATURE_FTP_WRITE
762 handle_upload_common(int is_append, int is_unique)
764 char *tempname = NULL;
768 off_t offset = G.restart_pos;
771 if (!G.ftp_arg || !data_transfer_checks_ok())
775 tempname = xstrdup("FILE: uniq.XXXXXX");
777 * XXX Use mkostemp here? vsftpd opens file with O_CREAT, O_WRONLY,
778 * O_APPEND and O_EXCL flags...
780 new_file_fd = mkstemp(tempname + 6);
782 /* XXX Do we need check if ftp_arg != NULL? */
783 if (!is_append && offset == 0)
784 new_file_fd = open(G.ftp_arg, O_CREAT | O_WRONLY | O_APPEND | O_NONBLOCK | O_TRUNC, 0666);
786 new_file_fd = open(G.ftp_arg, O_CREAT | O_WRONLY | O_APPEND | O_NONBLOCK, 0666);
789 if (new_file_fd < 0) {
790 cmdio_write(FTP_UPLOADFAIL, "Can't create file");
794 if (!is_append && offset != 0) {
795 /* warning, allows seek past end of file! Check for seek > size? */
796 xlseek(new_file_fd, offset, SEEK_SET);
800 remote_fd = get_remote_transfer_fd(tempname);
803 remote_fd = get_remote_transfer_fd("Ok to send data");
808 trans_ret = bb_copyfd_eof(remote_fd, new_file_fd);
809 ftpdataio_dispose_transfer_fd();
812 cmdio_write(FTP_BADSENDFILE, "Failure writing to local file");
814 cmdio_write_ok(FTP_TRANSFEROK);
825 if (!G.ftp_arg || mkdir(G.ftp_arg, 0777) != 0) {
826 cmdio_write(FTP_FILEFAIL, "Create directory operation failed");
829 cmdio_write_ok(FTP_MKDIROK);
835 if (!G.ftp_arg || rmdir(G.ftp_arg) != 0) {
836 cmdio_write(FTP_FILEFAIL, "Deletion failed");
839 cmdio_write_ok(FTP_RMDIROK);
845 if (!G.ftp_arg || unlink(G.ftp_arg) != 0) {
846 cmdio_write(FTP_FILEFAIL, "Deletion failed");
849 cmdio_write_ok(FTP_DELEOK);
857 /* Clear old value */
858 free(G.rnfr_filename);
859 G.rnfr_filename = NULL;
862 || stat(G.ftp_arg, &statbuf) != 0
863 /* || it isn't a regular file or a directory? */
865 cmdio_write(FTP_FILEFAIL, "RNFR command failed");
868 G.rnfr_filename = xstrdup(G.ftp_arg);
869 cmdio_write_ok(FTP_RNFROK);
877 /* If we didn't get a RNFR, throw a wobbly */
878 if (G.rnfr_filename == NULL || G.ftp_arg == NULL) {
879 cmdio_write(FTP_NEEDRNFR, "RNFR required first");
883 retval = rename(G.rnfr_filename, G.ftp_arg);
884 free(G.rnfr_filename);
885 G.rnfr_filename = NULL;
888 cmdio_write(FTP_FILEFAIL, "Rename failed");
891 cmdio_write_ok(FTP_RENAMEOK);
897 handle_upload_common(0, 0);
903 handle_upload_common(1, 0);
909 handle_upload_common(0, 1);
911 #endif /* ENABLE_FEATURE_FTP_WRITE */
913 int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
914 int ftpd_main(int argc UNUSED_PARAM, char **argv)
918 G.local_addr = get_sock_lsa(STDIN_FILENO);
920 /* This is confusing:
921 * bb_error_msg_and_die("stdin is not a socket");
924 /* Help text says that ftpd must be used as inetd service,
925 * which is by far the most usual cause of get_sock_lsa
929 G.opts = getopt32(argv, "v" USE_FEATURE_FTP_WRITE("w"));
931 openlog(applet_name, LOG_PID, LOG_DAEMON);
932 logmode |= LOGMODE_SYSLOG;
933 if (!(G.opts & OPT_v))
934 logmode = LOGMODE_SYSLOG;
937 xchdir(argv[optind]);
941 //umask(077); - admin can set umask before starting us
943 /* Signals. We'll always take -EPIPE rather than a rude signal, thanks */
944 signal(SIGPIPE, SIG_IGN);
946 /* Set up options on the command socket (do we need these all? why?) */
947 setsockopt(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY, &const_int_1, sizeof(const_int_1));
948 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
949 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE, &const_int_1, sizeof(const_int_1));
951 cmdio_write(FTP_GREET, "Welcome");
953 #ifdef IF_WE_WANT_TO_REQUIRE_LOGIN
955 smallint user_was_specified = 0;
957 uint32_t cmdval = cmdio_get_cmd_and_arg();
959 if (cmdval == const_USER) {
960 if (G.ftp_arg == NULL || strcasecmp(G.ftp_arg, "anonymous") != 0)
961 cmdio_write(FTP_LOGINERR, "Server is anonymous only");
963 user_was_specified = 1;
964 cmdio_write(FTP_GIVEPWORD, "Please specify the password");
966 } else if (cmdval == const_PASS) {
967 if (user_was_specified)
969 cmdio_write(FTP_NEEDUSER, "Login with USER");
970 } else if (cmdval == const_QUIT) {
971 cmdio_write(FTP_GOODBYE, "Goodbye");
974 cmdio_write(FTP_LOGINERR, "Login with USER and PASS");
978 cmdio_write_ok(FTP_LOGINOK);
981 /* RFC-959 Section 5.1
982 * The following commands and options MUST be supported by every
983 * server-FTP and user-FTP, except in cases where the underlying
984 * file system or operating system does not allow or support
985 * a particular command.
986 * Type: ASCII Non-print, IMAGE, LOCAL 8
988 * Structure: File, Record*
989 * (Record structure is REQUIRED only for hosts whose file
990 * systems support record structure).
992 * USER, PASS, ACCT, [bbox: ACCT not supported]
997 * CWD, CDUP, RMD, MKD, PWD,
1003 * The argument field is a Telnet string identifying the user's account.
1004 * The command is not necessarily related to the USER command, as some
1005 * sites may require an account for login and others only for specific
1006 * access, such as storing files. In the latter case the command may
1007 * arrive at any time.
1008 * There are reply codes to differentiate these cases for the automation:
1009 * when account information is required for login, the response to
1010 * a successful PASSword command is reply code 332. On the other hand,
1011 * if account information is NOT required for login, the reply to
1012 * a successful PASSword command is 230; and if the account information
1013 * is needed for a command issued later in the dialogue, the server
1014 * should return a 332 or 532 reply depending on whether it stores
1015 * (pending receipt of the ACCounT command) or discards the command,
1020 uint32_t cmdval = cmdio_get_cmd_and_arg();
1022 if (cmdval == const_QUIT) {
1023 cmdio_write(FTP_GOODBYE, "Goodbye");
1026 if (cmdval == const_PWD)
1028 else if (cmdval == const_CWD)
1030 else if (cmdval == const_CDUP) /* cd .. */
1032 else if (cmdval == const_PASV)
1034 else if (cmdval == const_RETR)
1036 else if (cmdval == const_NOOP)
1037 cmdio_write_ok(FTP_NOOPOK);
1038 else if (cmdval == const_SYST)
1039 cmdio_write(FTP_SYSTOK, "UNIX Type: L8");
1040 else if (cmdval == const_HELP)
1042 else if (cmdval == const_LIST) /* ls -l */
1044 else if (cmdval == const_TYPE)
1046 else if (cmdval == const_PORT)
1048 else if (cmdval == const_REST)
1050 else if (cmdval == const_NLST) /* "name list", bare ls */
1052 else if (cmdval == const_STRU) {
1054 // && (G.ftp_arg[0] | 0x20) == 'f'
1055 // && G.ftp_arg[1] == '\0'
1057 cmdio_write(FTP_STRUOK, "Command ignored");
1059 // cmdio_write(FTP_BADSTRU, "Bad STRU command");
1060 } else if (cmdval == const_MODE) {
1062 // && (G.ftp_arg[0] | 0x20) == 's'
1063 // && G.ftp_arg[1] == '\0'
1065 cmdio_write(FTP_MODEOK, "Command ignored");
1067 // cmdio_write(FTP_BADMODE, "Bad MODE command");
1069 else if (cmdval == const_ALLO)
1070 cmdio_write(FTP_ALLOOK, "Command ignored");
1071 else if (cmdval == const_STAT) {
1072 if (G.ftp_arg == NULL)
1076 } else if (cmdval == const_USER) {
1077 /* FTP_LOGINERR confuses clients: */
1078 /* cmdio_write(FTP_LOGINERR, "Can't change to another user"); */
1079 cmdio_write(FTP_GIVEPWORD, "Command ignored");
1080 } else if (cmdval == const_PASS)
1081 cmdio_write(FTP_LOGINOK, "Command ignored");
1082 #if ENABLE_FEATURE_FTP_WRITE
1083 else if (G.opts & OPT_w) {
1084 if (cmdval == const_STOR)
1086 else if (cmdval == const_MKD)
1088 else if (cmdval == const_RMD)
1090 else if (cmdval == const_DELE)
1092 else if (cmdval == const_RNFR) /* "rename from" */
1094 else if (cmdval == const_RNTO) /* "rename to" */
1096 else if (cmdval == const_APPE)
1098 else if (cmdval == const_STOU) /* "store unique" */
1103 else if (cmdval == const_STOR
1104 || cmdval == const_MKD
1105 || cmdval == const_RMD
1106 || cmdval == const_DELE
1107 || cmdval == const_RNFR
1108 || cmdval == const_RNTO
1109 || cmdval == const_APPE
1110 || cmdval == const_STOU
1112 cmdio_write(FTP_NOPERM, "Permission denied");
1116 /* Which unsupported commands were seen in the wild
1117 * (doesn't necessarily mean "we must support them")
1118 * wget 1.11.4: SIZE - todo.
1119 * lftp 3.6.3: MDTM - works fine without it anyway.
1121 cmdio_write(FTP_BADCMD, "Unknown command");