Marcelo Rebonatto / Mbed 2 deprecated PMED_Tempo

Dependencies:   EthernetInterface mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers telnet_remove.cpp Source File

telnet_remove.cpp

00001 #include "TelnetServer.h"
00002 
00003 char *header_msg_remove = "File removed successfully\r\n\r\n";
00004 char *wrong_args_msg_remove = "Wrong number of arguments.\r\n\r\nUsage: remove <filename>\r\n";
00005 char *file_not_found_msg_remove = "File not found.\r\n\r\n";
00006 
00007 extern LocalFileSystem local;
00008 
00009 int TelnetServer::RemoveCommand(TCPSocketConnection *conn,char** argv,int argc)
00010 {
00011 
00012     if(argc != 2)
00013     {
00014         conn->send(wrong_args_msg_remove,strlen(wrong_args_msg_remove));
00015         return 0;
00016     }
00017 
00018     char fullpath[256];
00019     strcpy(fullpath,"/local/");
00020     strcat(fullpath,argv[1]);
00021     printf("File = %s\n",fullpath);  
00022     FILE* f = fopen(fullpath,"r");
00023     if(f == NULL)
00024     {
00025         conn->send(file_not_found_msg_remove,strlen(file_not_found_msg_remove));
00026         return 0;
00027     }
00028 
00029     fclose(f);
00030 
00031     local.remove(argv[1]);
00032 
00033     conn->send(header_msg_remove,strlen(header_msg_remove));
00034 
00035     return 0;
00036 }