MCPcopy Create free account
hub / github.com/SmingHub/Sming / onCommand

Method onCommand

Sming/Components/Network/src/Network/Ftp/FtpServerConnection.cpp:215–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213}
214
215void FtpServerConnection::onCommand(String cmd, String data)
216{
217 auto command = parseCommand(cmd);
218 switch(command) {
219 // We ready to quit always :)
220 case Command::QUIT:
221 response(221); // Service closing control connection
222 close();
223 break;
224
225 // Strong security check :)
226 case Command::USER:
227 // Authenticate or re-authenticate, wiping existing credentials
228 user = User{};
229 user.name = data;
230 response(331); // User name OK, need password
231 break;
232
233 case Command::PASS: {
234 if(!user.name) {
235 response(332); // Need account for login
236 } else {
237 user.role = server.validateUser(user.name.c_str(), data.c_str());
238 response(user.isValid() ? 230 : 430);
239 }
240 user.name = nullptr;
241 break;
242 }
243
244 case Command::SYST:
245 response(215, F("Windows_NT: Sming Framework")); // Why not? It's look like Windows :)
246 break;
247
248 case Command::PWD:
249 case Command::XPWD: {
250 String s;
251 s += "\"/";
252 s += cwd.c_str();
253 s += '"';
254 response(257, s);
255 break;
256 }
257
258 case Command::PORT:
259 cmdPort(data);
260 break;
261
262 case Command::CWD:
263 case Command::XCWD: {
264 String path = resolvePath(data.c_str());
265 if(!checkFileAccess(path.c_str(), IFS::OpenFlag::Read)) {
266 break;
267 }
268 debug_i("CWD: '%s'", path.c_str());
269 FileStat stat;
270 if(getFileSystem()->stat(path, stat) == FS_OK && stat.isDir()) {
271 cwd = path;
272 response(250, F("directory changed to /") + cwd.c_str()); // OK

Callers

nothing calls this directly

Calls 14

parseCommandFunction · 0.85
getFileSystemFunction · 0.85
dirnameFunction · 0.85
validateUserMethod · 0.80
renameMethod · 0.80
toUpperCaseMethod · 0.80
FFunction · 0.50
StringClass · 0.50
c_strMethod · 0.45
isValidMethod · 0.45
statMethod · 0.45
getErrorStringMethod · 0.45

Tested by

no test coverage detected