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);
206 /* Simple commands */
211 char *cwd, *promoted_cwd, *response;
213 cwd = xrealloc_getcwd_or_warn(NULL);
217 /* We have to promote each " to "" */
218 promoted_cwd = replace_text(cwd, '\"', "\"\"");
220 response = xasprintf("\"%s\"", promoted_cwd);
222 cmdio_write(FTP_PWDOK, response);
229 if (!G.ftp_arg || chdir(G.ftp_arg) != 0) {
230 cmdio_write(FTP_FILEFAIL, "Can't change directory");
233 cmdio_write_ok(FTP_CWDOK);
239 G.ftp_arg = (char*)"..";
247 && ( ((G.ftp_arg[0] | 0x20) == 'i' && G.ftp_arg[1] == '\0')
248 || !strcasecmp(G.ftp_arg, "L8")
249 || !strcasecmp(G.ftp_arg, "L 8")
252 cmdio_write_ok(FTP_TYPEOK);
254 cmdio_write(FTP_BADCMD, "Unrecognised TYPE command");
261 cmdio_write_hyphen(FTP_STATOK, "FTP server status:");
262 cmdio_write_raw(" TYPE: BINARY\r\n");
263 cmdio_write_ok(FTP_STATOK);
269 cmdio_write_hyphen(FTP_HELP, "Recognized commands:");
270 cmdio_write_raw(" ALLO CDUP CWD HELP LIST\r\n"
271 " MODE NLST NOOP PASS PASV PORT PWD QUIT\r\n"
272 " REST RETR STAT STRU SYST TYPE USER\r\n"
273 #if ENABLE_FEATURE_FTP_WRITE
274 " APPE DELE MKD RMD RNFR RNTO STOR STOU\r\n"
277 cmdio_write(FTP_HELP, "Help OK");
280 /* Download commands */
283 init_data_sock_params(int sock_fd)
285 struct linger linger;
289 memset(&linger, 0, sizeof(linger));
291 linger.l_linger = 32767;
293 setsockopt(sock_fd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
294 setsockopt(sock_fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
298 ftpdataio_get_pasv_fd(void)
302 remote_fd = accept(G.pasv_listen_fd, NULL, 0);
305 cmdio_write(FTP_BADSENDCONN, "Can't establish connection");
309 init_data_sock_params(remote_fd);
314 ftpdataio_get_port_fd(void)
318 /* Do we want to die or print error to client? */
319 remote_fd = xconnect_stream(G.port_addr);
321 init_data_sock_params(remote_fd);
326 ftpdataio_dispose_transfer_fd(void)
328 /* This close() blocks because we set SO_LINGER */
329 if (G.data_fd > STDOUT_FILENO) {
330 if (close(G.data_fd) < 0) {
331 /* Do it again without blocking. */
332 struct linger linger;
334 memset(&linger, 0, sizeof(linger));
335 setsockopt(G.data_fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
345 return (G.port_addr != NULL);
351 return (G.pasv_listen_fd > STDOUT_FILENO);
355 get_remote_transfer_fd(const char *p_status_msg)
360 remote_fd = ftpdataio_get_pasv_fd();
362 remote_fd = ftpdataio_get_port_fd();
367 cmdio_write(FTP_DATACONN, p_status_msg);
372 data_transfer_checks_ok(void)
374 if (!pasv_active() && !port_active()) {
375 cmdio_write(FTP_BADSENDCONN, "Use PORT or PASV first");
383 port_pasv_cleanup(void)
387 if (G.pasv_listen_fd > STDOUT_FILENO)
388 close(G.pasv_listen_fd);
389 G.pasv_listen_fd = -1;
395 int bind_retries = 10;
397 enum { min_port = 1024, max_port = 65535 };
398 char *addr, *response;
402 G.pasv_listen_fd = xsocket(G.local_addr->u.sa.sa_family, SOCK_STREAM, 0);
403 setsockopt_reuseaddr(G.pasv_listen_fd);
405 /* TODO bind() with port == 0 and then call getsockname */
406 while (--bind_retries) {
407 port = rand() % max_port;
408 if (port < min_port) {
412 set_nport(G.local_addr, htons(port));
413 /* We don't want to use xbind, it'll die if port is in use */
414 if (bind(G.pasv_listen_fd, &G.local_addr->u.sa, G.local_addr->len) != 0) {
415 /* do we want check if errno == EADDRINUSE ? */
418 xlisten(G.pasv_listen_fd, 1);
423 bb_error_msg_and_die("can't create pasv socket");
425 addr = xmalloc_sockaddr2dotted_noport(&G.local_addr->u.sa);
426 replace_char(addr, '.', ',');
428 response = xasprintf("Entering Passive Mode (%s,%u,%u)",
429 addr, (int)(port >> 8), (int)(port & 255));
432 cmdio_write(FTP_PASVOK, response);
440 char *raw, *port_part;
441 len_and_sockaddr *lsa = NULL;
448 * xatou16 will accept wrong input,
449 * xatou16 will exit instead of generating error to peer
452 port_part = strrchr(raw, ',');
453 if (port_part == NULL)
455 port = xatou16(&port_part[1]);
458 port_part = strrchr(raw, ',');
459 if (port_part == NULL)
461 port |= xatou16(&port_part[1]) << 8;
464 replace_char(raw, ',', '.');
465 lsa = xdotted2sockaddr(raw, port);
469 cmdio_write(FTP_BADCMD, "Illegal PORT command");
474 cmdio_write_ok(FTP_PORTOK);
480 /* When ftp_arg == NULL simply restart from beginning */
481 G.restart_pos = G.ftp_arg ? xatoi_u(G.ftp_arg) : 0;
482 cmdio_write_ok(FTP_RESTOK);
489 int trans_ret, retval;
492 off_t offset = G.restart_pos;
497 if (!data_transfer_checks_ok())
500 /* O_NONBLOCK is useful if file happens to be a device node */
501 opened_file = G.ftp_arg ? open(G.ftp_arg, O_RDONLY | O_NONBLOCK) : -1;
502 if (opened_file < 0) {
503 cmdio_write(FTP_FILEFAIL, "Can't open file");
507 retval = fstat(opened_file, &statbuf);
508 if (retval < 0 || !S_ISREG(statbuf.st_mode)) {
509 /* Note - pretend open failed */
510 cmdio_write(FTP_FILEFAIL, "Can't open file");
514 /* Now deactive O_NONBLOCK, otherwise we have a problem on DMAPI filesystems
517 ndelay_off(opened_file);
519 /* Set the download offset (from REST) if any */
521 xlseek(opened_file, offset, SEEK_SET);
523 response = xasprintf(
524 "Opening BINARY mode data connection for %s (%"OFF_FMT"u bytes)",
525 G.ftp_arg, statbuf.st_size);
526 remote_fd = get_remote_transfer_fd(response);
529 goto port_pasv_cleanup_out;
531 trans_ret = bb_copyfd_eof(opened_file, remote_fd);
532 ftpdataio_dispose_transfer_fd();
534 cmdio_write(FTP_BADSENDFILE, "Error sending local file");
536 cmdio_write_ok(FTP_TRANSFEROK);
538 port_pasv_cleanup_out:
548 statbuf_getperms(const struct stat *statbuf)
551 enum { r = 'r', w = 'w', x = 'x', s = 's', S = 'S' };
554 memset(perms, '-', 10);
557 switch (statbuf->st_mode & S_IFMT) {
558 case S_IFREG: perms[0] = '-'; break;
559 case S_IFDIR: perms[0] = 'd'; break;
560 case S_IFLNK: perms[0] = 'l'; break;
561 case S_IFIFO: perms[0] = 'p'; break;
562 case S_IFSOCK: perms[0] = s; break;
563 case S_IFCHR: perms[0] = 'c'; break;
564 case S_IFBLK: perms[0] = 'b'; break;
567 if (statbuf->st_mode & S_IRUSR) perms[1] = r;
568 if (statbuf->st_mode & S_IWUSR) perms[2] = w;
569 if (statbuf->st_mode & S_IXUSR) perms[3] = x;
570 if (statbuf->st_mode & S_IRGRP) perms[4] = r;
571 if (statbuf->st_mode & S_IWGRP) perms[5] = w;
572 if (statbuf->st_mode & S_IXGRP) perms[6] = x;
573 if (statbuf->st_mode & S_IROTH) perms[7] = r;
574 if (statbuf->st_mode & S_IWOTH) perms[8] = w;
575 if (statbuf->st_mode & S_IXOTH) perms[9] = x;
576 if (statbuf->st_mode & S_ISUID) perms[3] = (perms[3] == x) ? s : S;
577 if (statbuf->st_mode & S_ISGID) perms[6] = (perms[6] == x) ? s : S;
578 if (statbuf->st_mode & S_ISVTX) perms[9] = (perms[9] == x) ? 't' : 'T';
586 write_filestats(int fd, const char *filename,
587 const struct stat *statbuf)
590 char *stats, *lnkname = NULL, *perms;
595 const char *format = "%b %d %H:%M";
597 name = bb_get_last_path_component_nostrip(filename);
599 if (statbuf != NULL) {
600 size = statbuf->st_size;
602 if (S_ISLNK(statbuf->st_mode))
603 /* Damn symlink... */
604 lnkname = xmalloc_readlink(filename);
606 tm = gmtime(&statbuf->st_mtime);
607 retval = strftime(timestr, sizeof(timestr), format, tm);
609 bb_error_msg_and_die("strftime");
611 timestr[sizeof(timestr) - 1] = '\0';
613 perms = statbuf_getperms(statbuf);
615 stats = xasprintf("%s %u\tftp ftp %"OFF_FMT"u\t%s %s",
616 perms, (int) statbuf->st_nlink,
617 size, timestr, name);
621 stats = xstrdup(name);
623 xwrite_str(fd, stats);
625 if (lnkname != NULL) {
626 xwrite_str(fd, " -> ");
627 xwrite_str(fd, lnkname);
630 xwrite_str(fd, "\r\n");
634 write_dirstats(int fd, const char *dname, int details)
637 struct dirent *dirent;
641 dir = xopendir(dname);
644 dirent = readdir(dir);
648 /* Ignore . and .. */
649 if (dirent->d_name[0] == '.') {
650 if (dirent->d_name[1] == '\0'
651 || (dirent->d_name[1] == '.' && dirent->d_name[2] == '\0')
658 filename = xasprintf("%s/%s", dname, dirent->d_name);
659 if (lstat(filename, &statbuf) != 0) {
664 filename = xstrdup(dirent->d_name);
666 write_filestats(fd, filename, details ? &statbuf : NULL);
674 handle_dir_common(int full_details, int stat_cmd)
679 if (!stat_cmd && !data_transfer_checks_ok())
684 cmdio_write_hyphen(FTP_STATFILE_OK, "Status follows:");
686 fd = get_remote_transfer_fd("Here comes the directory listing");
692 if (lstat(G.ftp_arg, &statbuf) != 0) {
693 /* Dir doesn't exist => return ok to client */
696 if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode))
697 write_filestats(fd, G.ftp_arg, &statbuf);
698 else if (S_ISDIR(statbuf.st_mode))
699 write_dirstats(fd, G.ftp_arg, full_details);
701 write_dirstats(fd, ".", full_details);
704 /* Well, if we can't open directory/file it doesn't matter */
706 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);
731 /* Upload commands */
733 #if ENABLE_FEATURE_FTP_WRITE
737 if (!G.ftp_arg || mkdir(G.ftp_arg, 0777) != 0) {
738 cmdio_write(FTP_FILEFAIL, "Create directory operation failed");
741 cmdio_write_ok(FTP_MKDIROK);
747 if (!G.ftp_arg || rmdir(G.ftp_arg) != 0) {
748 cmdio_write(FTP_FILEFAIL, "Deletion failed");
751 cmdio_write_ok(FTP_RMDIROK);
757 if (!G.ftp_arg || unlink(G.ftp_arg) != 0) {
758 cmdio_write(FTP_FILEFAIL, "Deletion failed");
761 cmdio_write_ok(FTP_DELEOK);
769 /* Clear old value */
770 free(G.rnfr_filename);
771 G.rnfr_filename = NULL;
774 || stat(G.ftp_arg, &statbuf) != 0
775 /* || it isn't a regular file or a directory? */
777 cmdio_write(FTP_FILEFAIL, "RNFR command failed");
780 G.rnfr_filename = xstrdup(G.ftp_arg);
781 cmdio_write_ok(FTP_RNFROK);
789 /* If we didn't get a RNFR, throw a wobbly */
790 if (G.rnfr_filename == NULL || G.ftp_arg == NULL) {
791 cmdio_write(FTP_NEEDRNFR, "RNFR required first");
795 retval = rename(G.rnfr_filename, G.ftp_arg);
796 free(G.rnfr_filename);
797 G.rnfr_filename = NULL;
800 cmdio_write(FTP_FILEFAIL, "Rename failed");
803 cmdio_write_ok(FTP_RENAMEOK);
807 handle_upload_common(int is_append, int is_unique)
809 char *tempname = NULL;
815 offset = G.restart_pos;
818 if (!data_transfer_checks_ok())
823 tempname = xstrdup("FILE: uniq.XXXXXX");
824 local_file_fd = mkstemp(tempname + 6);
825 } else if (G.ftp_arg) {
826 int flags = O_WRONLY | O_CREAT | O_TRUNC;
828 flags = O_WRONLY | O_CREAT | O_APPEND;
830 flags = O_WRONLY | O_CREAT;
831 local_file_fd = open(G.ftp_arg, flags, 0666);
833 if (local_file_fd < 0) {
834 cmdio_write(FTP_UPLOADFAIL, "Can't create file");
838 /* TODO: paranoia: fstat it, refuse to do anything if it's not a regular file */
841 xlseek(local_file_fd, offset, SEEK_SET);
843 remote_fd = get_remote_transfer_fd(tempname ? tempname : "Ok to send data");
849 trans_ret = bb_copyfd_eof(remote_fd, local_file_fd);
850 ftpdataio_dispose_transfer_fd();
853 cmdio_write(FTP_BADSENDFILE, "Failure writing to local file");
855 cmdio_write_ok(FTP_TRANSFEROK);
859 close(local_file_fd);
865 handle_upload_common(0, 0);
872 handle_upload_common(1, 0);
879 handle_upload_common(0, 1);
881 #endif /* ENABLE_FEATURE_FTP_WRITE */
884 cmdio_get_cmd_and_arg(void)
891 len = 8 * 1024; /* Paranoia. Peer may send 1 gigabyte long cmd... */
892 G.ftp_cmp = cmd = xmalloc_reads(STDIN_FILENO, NULL, &len);
896 len = strlen(cmd) - 1;
897 while (len >= 0 && cmd[len] == '\r') {
902 G.ftp_arg = strchr(cmd, ' ');
903 if (G.ftp_arg != NULL) {
909 cmdval = (cmdval << 8) + ((unsigned char)*cmd++ & (unsigned char)~0x20);
914 int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
915 int ftpd_main(int argc UNUSED_PARAM, char **argv)
919 G.local_addr = get_sock_lsa(STDIN_FILENO);
921 /* This is confusing:
922 * bb_error_msg_and_die("stdin is not a socket");
925 /* Help text says that ftpd must be used as inetd service,
926 * which is by far the most usual cause of get_sock_lsa
930 G.opts = getopt32(argv, "v" USE_FEATURE_FTP_WRITE("w"));
932 openlog(applet_name, LOG_PID, LOG_DAEMON);
933 logmode |= LOGMODE_SYSLOG;
934 if (!(G.opts & OPT_v))
935 logmode = LOGMODE_SYSLOG;
938 xchdir(argv[optind]);
942 //umask(077); - admin can set umask before starting us
944 /* Signals. We'll always take -EPIPE rather than a rude signal, thanks */
945 signal(SIGPIPE, SIG_IGN);
947 /* Set up options on the command socket (do we need these all? why?) */
948 setsockopt(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY, &const_int_1, sizeof(const_int_1));
949 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
950 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE, &const_int_1, sizeof(const_int_1));
952 cmdio_write(FTP_GREET, "Welcome");
954 #ifdef IF_WE_WANT_TO_REQUIRE_LOGIN
956 smallint user_was_specified = 0;
958 uint32_t cmdval = cmdio_get_cmd_and_arg();
960 if (cmdval == const_USER) {
961 if (G.ftp_arg == NULL || strcasecmp(G.ftp_arg, "anonymous") != 0)
962 cmdio_write(FTP_LOGINERR, "Server is anonymous only");
964 user_was_specified = 1;
965 cmdio_write(FTP_GIVEPWORD, "Please specify the password");
967 } else if (cmdval == const_PASS) {
968 if (user_was_specified)
970 cmdio_write(FTP_NEEDUSER, "Login with USER");
971 } else if (cmdval == const_QUIT) {
972 cmdio_write(FTP_GOODBYE, "Goodbye");
975 cmdio_write(FTP_LOGINERR, "Login with USER and PASS");
979 cmdio_write_ok(FTP_LOGINOK);
982 /* RFC-959 Section 5.1
983 * The following commands and options MUST be supported by every
984 * server-FTP and user-FTP, except in cases where the underlying
985 * file system or operating system does not allow or support
986 * a particular command.
987 * Type: ASCII Non-print, IMAGE, LOCAL 8
989 * Structure: File, Record*
990 * (Record structure is REQUIRED only for hosts whose file
991 * systems support record structure).
993 * USER, PASS, ACCT, [bbox: ACCT not supported]
998 * CWD, CDUP, RMD, MKD, PWD,
1004 * The argument field is a Telnet string identifying the user's account.
1005 * The command is not necessarily related to the USER command, as some
1006 * sites may require an account for login and others only for specific
1007 * access, such as storing files. In the latter case the command may
1008 * arrive at any time.
1009 * There are reply codes to differentiate these cases for the automation:
1010 * when account information is required for login, the response to
1011 * a successful PASSword command is reply code 332. On the other hand,
1012 * if account information is NOT required for login, the reply to
1013 * a successful PASSword command is 230; and if the account information
1014 * is needed for a command issued later in the dialogue, the server
1015 * should return a 332 or 532 reply depending on whether it stores
1016 * (pending receipt of the ACCounT command) or discards the command,
1021 uint32_t cmdval = cmdio_get_cmd_and_arg();
1023 if (cmdval == const_QUIT) {
1024 cmdio_write(FTP_GOODBYE, "Goodbye");
1027 if (cmdval == const_PWD)
1029 else if (cmdval == const_CWD)
1031 else if (cmdval == const_CDUP) /* cd .. */
1033 else if (cmdval == const_PASV)
1035 else if (cmdval == const_RETR)
1037 else if (cmdval == const_NOOP)
1038 cmdio_write_ok(FTP_NOOPOK);
1039 else if (cmdval == const_SYST)
1040 cmdio_write(FTP_SYSTOK, "UNIX Type: L8");
1041 else if (cmdval == const_HELP)
1043 else if (cmdval == const_LIST) /* ls -l */
1045 else if (cmdval == const_TYPE)
1047 else if (cmdval == const_PORT)
1049 else if (cmdval == const_REST)
1051 else if (cmdval == const_NLST) /* "name list", bare ls */
1053 else if (cmdval == const_STRU) {
1055 // && (G.ftp_arg[0] | 0x20) == 'f'
1056 // && G.ftp_arg[1] == '\0'
1058 cmdio_write(FTP_STRUOK, "Command ignored");
1060 // cmdio_write(FTP_BADSTRU, "Bad STRU command");
1061 } else if (cmdval == const_MODE) {
1063 // && (G.ftp_arg[0] | 0x20) == 's'
1064 // && G.ftp_arg[1] == '\0'
1066 cmdio_write(FTP_MODEOK, "Command ignored");
1068 // cmdio_write(FTP_BADMODE, "Bad MODE command");
1070 else if (cmdval == const_ALLO)
1071 cmdio_write(FTP_ALLOOK, "Command ignored");
1072 else if (cmdval == const_STAT) {
1073 if (G.ftp_arg == NULL)
1077 } else if (cmdval == const_USER) {
1078 /* FTP_LOGINERR confuses clients: */
1079 /* cmdio_write(FTP_LOGINERR, "Can't change to another user"); */
1080 cmdio_write(FTP_GIVEPWORD, "Command ignored");
1081 } else if (cmdval == const_PASS)
1082 cmdio_write(FTP_LOGINOK, "Command ignored");
1083 #if ENABLE_FEATURE_FTP_WRITE
1084 else if (G.opts & OPT_w) {
1085 if (cmdval == const_STOR)
1087 else if (cmdval == const_MKD)
1089 else if (cmdval == const_RMD)
1091 else if (cmdval == const_DELE)
1093 else if (cmdval == const_RNFR) /* "rename from" */
1095 else if (cmdval == const_RNTO) /* "rename to" */
1097 else if (cmdval == const_APPE)
1099 else if (cmdval == const_STOU) /* "store unique" */
1104 else if (cmdval == const_STOR
1105 || cmdval == const_MKD
1106 || cmdval == const_RMD
1107 || cmdval == const_DELE
1108 || cmdval == const_RNFR
1109 || cmdval == const_RNTO
1110 || cmdval == const_APPE
1111 || cmdval == const_STOU
1113 cmdio_write(FTP_NOPERM, "Permission denied");
1117 /* Which unsupported commands were seen in the wild?
1118 * (doesn't necessarily mean "we must support them")
1119 * wget 1.11.4: SIZE - todo.
1120 * lftp 3.6.3: MDTM - works fine without it anyway.
1121 * IPv6-style PASV: "EPSV 2"
1123 cmdio_write(FTP_BADCMD, "Unknown command");