From 24ec52babbbb6290d5d86a7d46fd94ea06ed906d Mon Sep 17 00:00:00 2001 From: mtheall Date: Sun, 23 Nov 2014 23:54:12 -0600 Subject: [PATCH] implement DELE --- source/ftp.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/source/ftp.c b/source/ftp.c index e7c3e1e..53b6368 100644 --- a/source/ftp.c +++ b/source/ftp.c @@ -1612,12 +1612,38 @@ FTP_DECLARE(CWD) FTP_DECLARE(DELE) { - /* TODO */ +#ifdef _3DS + Result ret; +#else + int rc; +#endif + console_print("%s %s\n", __func__, args ? args : ""); ftp_session_set_state(session, COMMAND_STATE); - return ftp_send_response(session, 502, "unavailable\r\n"); + if(validate_path(args) != 0) + return ftp_send_response(session, 553, "invalid file name\r\n"); + + build_path(session, args); + +#ifdef _3DS + ret = FSUSER_DeleteFile(NULL, sdmcArchive, FS_makePath(PATH_CHAR, session->buffer)); + if(ret != 0) + { + console_print("FSUSER_DeleteFile: 0x%08X\n", (unsigned int)ret); + return ftp_send_response(session, 550, "failed to delete file\r\n"); + } +#else + rc = unlink(session->buffer); + if(rc != 0) + { + console_print("unlink: %s\n", strerror(errno)); + return ftp_send_response(session, 550, "failed to delete file\r\n"); + } +#endif + + return ftp_send_response(session, 250, "OK\r\n"); } FTP_DECLARE(FEAT) @@ -1681,10 +1707,7 @@ FTP_DECLARE(MKD) ftp_session_set_state(session, COMMAND_STATE); if(validate_path(args) != 0) - { - ftp_session_set_state(session, COMMAND_STATE); return ftp_send_response(session, 553, "invalid file name\r\n"); - } build_path(session, args);