mirror of
https://github.com/kingk85/uFTP.git
synced 2025-07-17 09:16:11 +03:00
Implementation of commands MKD and RMD
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
dist/Debug/GNU-Linux/uftp
vendored
BIN
dist/Debug/GNU-Linux/uftp
vendored
Binary file not shown.
@ -425,6 +425,87 @@ int parseCommandRest(clientDataType *theClientData)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int parseCommandMkd(clientDataType *theClientData)
|
||||
{
|
||||
int returnStatus = 0;
|
||||
char *theDirectoryFilename;
|
||||
dynamicStringDataType theResponse;
|
||||
dynamicStringDataType mkdFileName;
|
||||
|
||||
theDirectoryFilename = getFtpCommandArg("MKD", theClientData->theCommandReceived);
|
||||
|
||||
|
||||
cleanDynamicStringDataType(&theResponse, 1);
|
||||
cleanDynamicStringDataType(&mkdFileName, 1);
|
||||
|
||||
if (theDirectoryFilename[0] == '/')
|
||||
{
|
||||
setDynamicStringDataType(&mkdFileName, theDirectoryFilename, strlen(theDirectoryFilename));
|
||||
}
|
||||
else
|
||||
{
|
||||
setDynamicStringDataType(&mkdFileName, theClientData->login.absolutePath.text, theClientData->login.absolutePath.textLen);
|
||||
appendToDynamicStringDataType(&mkdFileName, "/", 1);
|
||||
appendToDynamicStringDataType(&mkdFileName, theDirectoryFilename, strlen(theDirectoryFilename));
|
||||
}
|
||||
|
||||
if (strlen(theDirectoryFilename) > 0)
|
||||
{
|
||||
printf("\nThe directory to make is: %s", mkdFileName.text);
|
||||
returnStatus = mkdir(mkdFileName.text, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
}
|
||||
|
||||
setDynamicStringDataType(&theResponse, "257 \"", strlen("257 \""));
|
||||
appendToDynamicStringDataType(&theResponse, theDirectoryFilename, strlen(theDirectoryFilename));
|
||||
appendToDynamicStringDataType(&theResponse, "\" : The directory was successfully created\r\n", strlen("\" : The directory was successfully created\r\n"));
|
||||
|
||||
write(theClientData->socketDescriptor, theResponse.text, theResponse.textLen);
|
||||
|
||||
cleanDynamicStringDataType(&theResponse, 0);
|
||||
cleanDynamicStringDataType(&mkdFileName, 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int parseCommandRmd(clientDataType *theClientData)
|
||||
{
|
||||
int returnStatus = 0;
|
||||
char *theDirectoryFilename;
|
||||
dynamicStringDataType theResponse;
|
||||
dynamicStringDataType mkdFileName;
|
||||
|
||||
theDirectoryFilename = getFtpCommandArg("RMD", theClientData->theCommandReceived);
|
||||
|
||||
cleanDynamicStringDataType(&theResponse, 1);
|
||||
cleanDynamicStringDataType(&mkdFileName, 1);
|
||||
|
||||
if (theDirectoryFilename[0] == '/')
|
||||
{
|
||||
setDynamicStringDataType(&mkdFileName, theDirectoryFilename, strlen(theDirectoryFilename));
|
||||
}
|
||||
else
|
||||
{
|
||||
setDynamicStringDataType(&mkdFileName, theClientData->login.absolutePath.text, theClientData->login.absolutePath.textLen);
|
||||
appendToDynamicStringDataType(&mkdFileName, "/", 1);
|
||||
appendToDynamicStringDataType(&mkdFileName, theDirectoryFilename, strlen(theDirectoryFilename));
|
||||
}
|
||||
|
||||
if (strlen(theDirectoryFilename) > 0)
|
||||
{
|
||||
printf("\nThe directory to make is: %s", mkdFileName.text);
|
||||
returnStatus = rmdir(mkdFileName.text);
|
||||
}
|
||||
|
||||
setDynamicStringDataType(&theResponse, "250 The directory was successfully removed\r\n", strlen("250 The directory was successfully removed\r\n"));
|
||||
write(theClientData->socketDescriptor, theResponse.text, theResponse.textLen);
|
||||
|
||||
cleanDynamicStringDataType(&theResponse, 0);
|
||||
cleanDynamicStringDataType(&mkdFileName, 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int parseCommandCdup(clientDataType *theClientData)
|
||||
{
|
||||
int i;
|
||||
@ -502,3 +583,16 @@ int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom
|
||||
fclose(retrFP);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
char *getFtpCommandArg(char * theCommand, char *theCommandString)
|
||||
{
|
||||
char *toReturn = theCommandString + strlen(theCommand);
|
||||
|
||||
while (toReturn[0] == ' ')
|
||||
{
|
||||
toReturn += 1;
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
@ -33,10 +33,14 @@ int parseCommandTypeI(clientDataType *theClientData);
|
||||
int parseCommandPasv(ftpDataType * data, int socketId);
|
||||
int parseCommandList(ftpDataType * data, int socketId);
|
||||
int parseCommandRetr(ftpDataType * data, int socketId);
|
||||
int parseCommandMkd(clientDataType *theClientData);
|
||||
int parseCommandRmd(clientDataType *theClientData);
|
||||
int parseCommandStor(ftpDataType * data, int socketId);
|
||||
int parseCommandCwd(clientDataType *theClientData);
|
||||
int parseCommandCdup(clientDataType *theClientData);
|
||||
|
||||
int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom);
|
||||
char *getFtpCommandArg(char * theCommand, char *theCommandString);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -65,7 +65,6 @@ void setDynamicStringDataType(dynamicStringDataType *dynamicString, char *theStr
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void appendToDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen)
|
||||
{
|
||||
printf("\n Appending in %s --> %s", dynamicString->text, theString);
|
||||
|
79
ftpServer.c
79
ftpServer.c
@ -668,7 +668,84 @@ static int processCommand(int processingElement)
|
||||
printf("\nSTOR COMMAND RECEIVED");
|
||||
toReturn = parseCommandStor(&ftpData, processingElement);
|
||||
}
|
||||
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "MKD", strlen("MKD")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "mkd", strlen("mkd")) == 0)
|
||||
{
|
||||
printf("\nMKD command received");
|
||||
toReturn = parseCommandMkd(&ftpData.clients[processingElement]);
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "ABOR", strlen("ABOR")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "abor", strlen("abor")) == 0)
|
||||
{
|
||||
printf("\nABOR command received");
|
||||
//To implement
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "DELE", strlen("DELE")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "dele", strlen("dele")) == 0)
|
||||
{
|
||||
printf("\nDELE command received");
|
||||
//To implement
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "MTDM", strlen("MTDM")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "mtdm", strlen("mtdm")) == 0)
|
||||
{
|
||||
printf("\nMTDM command received");
|
||||
//To implement
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "NLST", strlen("NLST")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "nlst", strlen("nlst")) == 0)
|
||||
{
|
||||
printf("\nNLST command received");
|
||||
//To implement
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "PORT", strlen("PORT")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "port", strlen("port")) == 0)
|
||||
{
|
||||
printf("\nPORT command received");
|
||||
//To implement
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "QUIT", strlen("QUIT")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "quit", strlen("quit")) == 0)
|
||||
{
|
||||
printf("\nQUIT command received");
|
||||
//To implement
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "RMD", strlen("RMD")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "rmd", strlen("rmd")) == 0)
|
||||
{
|
||||
printf("\nRMD command received");
|
||||
toReturn = parseCommandRmd(&ftpData.clients[processingElement]);
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "RNFR", strlen("RNFR")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "rnfr", strlen("rnfr")) == 0)
|
||||
{
|
||||
printf("\nRNFR command received");
|
||||
//To implement
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "RNTO", strlen("RNTO")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "rnto", strlen("rnto")) == 0)
|
||||
{
|
||||
printf("\nRNTO command received");
|
||||
//To implement
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "SIZE", strlen("SIZE")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "size", strlen("size")) == 0)
|
||||
{
|
||||
printf("\nSIZE command received");
|
||||
//To implement
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "APPE", strlen("APPE")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "appe", strlen("appe")) == 0)
|
||||
{
|
||||
printf("\nAPPE command received");
|
||||
//To implement
|
||||
}
|
||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "NOOP", strlen("NOOP")) == 0 ||
|
||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "noop", strlen("noop")) == 0)
|
||||
{
|
||||
printf("\nNOOP command received");
|
||||
//To implement
|
||||
}
|
||||
//REST COMMAND
|
||||
//REST 0
|
||||
//350 Restarting at 0
|
||||
|
@ -6,6 +6,8 @@
|
||||
</data>
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group/>
|
||||
<group>
|
||||
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpCommandsElaborate.h</file>
|
||||
</group>
|
||||
</open-files>
|
||||
</project-private>
|
||||
|
Reference in New Issue
Block a user