2 * User FTP Server, Share folders over FTP without being root.
3 * Copyright (C) 2008 Isaac Jurado
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28 * Main FTP server loop. The switch should be converted to an indexed jump
29 * because the command values are consecutive integers. Thus avoiding the
30 * multiple string comparisons.
32 void command_loop (void)
37 switch (next_command())
40 * Straightforward implementations.
43 reply_c("200 I'm alive, don't worry\r\n");
47 reply_c("211-Feature list:\r\n"
49 "211- REST STREAM\r\n"
56 reply_c("215 UNIX Type: L8\r\n");
61 reply_c("230 I don't care.\r\n");
65 reply_c("501 Option not understood.\r\n");
70 reply_c("202 Unimplemented, ignored.\r\n");
74 reply_c("220 Nothing to REIN.\r\n");
78 * A bit more complex commands.
81 if (toupper(SS
.arg
[0]) == 'S')
82 reply_c("200 MODE set to stream.\r\n");
84 reply_c("504 Mode not supported.\r\n");
88 if (toupper(SS
.arg
[0]) == 'F')
89 reply_c("200 STRUcture set to file.\r\n");
91 reply_c("504 Structure not supported.\r\n");
95 switch (toupper(SS
.arg
[0]))
99 case 'L': reply_c("200 Whatever.\r\n"); break;
100 default : reply_c("504 Type not supported.\r\n");
105 l
= snprintf(SS
.aux
, LINE_SIZE
, "257 \"%s\"\r\n", &SS
.cwd
[1]);
110 /* We don't need str_to_ll() as sscanf() does de job */
111 sscanf(SS
.arg
, "%lld", (long long *) &SS
.file_offset
);
112 l
= snprintf(SS
.aux
, LINE_SIZE
, "350 Got it (%lld).\r\n",
113 (long long) SS
.file_offset
);
118 reply_c("221 Goodbye.\r\n");
119 e
= close(SS
.control_sk
);
121 error("Closing control channel");
123 if (SS
.passive_sk
!= -1)
125 e
= close(SS
.passive_sk
);
127 error("Closing passive socket");
133 * Complex commands implemented separately.
136 parse_port_argument();
168 reply_c("500 Command unrecognized.\r\n");
172 reply_c("502 Command not implemented.\r\n");