mirror of
https://github.com/kingk85/uFTP.git
synced 2025-04-21 00:48:37 +03:00
Implemented command ABOR
This commit is contained in:
1
MakeSimple
Normal file
1
MakeSimple
Normal file
@ -0,0 +1 @@
|
|||||||
|
#Standard GCC MakeFile to be continued...
|
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.
@ -218,6 +218,44 @@ int parseCommandPasv(ftpDataType * data, int socketId)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int parseCommandAbor(ftpDataType * data, int socketId)
|
||||||
|
{
|
||||||
|
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
|
||||||
|
|
||||||
|
/*
|
||||||
|
426 ABORT
|
||||||
|
226-Transfer aborted
|
||||||
|
226 3.406 seconds (measured here), 1.58 Mbytes per second
|
||||||
|
226 Since you see this ABOR must've succeeded
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (data->clients[socketId].pasvData.threadIsAlive == 1 &&
|
||||||
|
data->clients[socketId].pasvData.threadIsBusy == 1)
|
||||||
|
{
|
||||||
|
void *pReturn;
|
||||||
|
pthread_cancel(data->clients[socketId].pasvData.pasvThread);
|
||||||
|
pthread_join(data->clients[socketId].pasvData.pasvThread, &pReturn);
|
||||||
|
printf("\nThread has been cancelled due to ABOR request.");
|
||||||
|
|
||||||
|
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
|
||||||
|
sprintf(theResponse, "426 ABORT\r\n");
|
||||||
|
write(data->clients[socketId].socketDescriptor, theResponse, strlen(theResponse));
|
||||||
|
|
||||||
|
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
|
||||||
|
sprintf(theResponse, "226 Transfer aborted\r\n");
|
||||||
|
write(data->clients[socketId].socketDescriptor, theResponse, strlen(theResponse));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
|
||||||
|
sprintf(theResponse, "226 Since you see this ABOR must've succeeded\r\n");
|
||||||
|
write(data->clients[socketId].socketDescriptor, theResponse, strlen(theResponse));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int parseCommandList(ftpDataType * data, int socketId)
|
int parseCommandList(ftpDataType * data, int socketId)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&data->clients[socketId].pasvData.conditionMutex);
|
pthread_mutex_lock(&data->clients[socketId].pasvData.conditionMutex);
|
||||||
@ -472,6 +510,47 @@ int parseCommandMkd(clientDataType *theClientData)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int parseCommandDele(clientDataType *theClientData)
|
||||||
|
{
|
||||||
|
int returnStatus = 0;
|
||||||
|
char *theFileToDelete;
|
||||||
|
dynamicStringDataType theResponse;
|
||||||
|
dynamicStringDataType deleFileName;
|
||||||
|
|
||||||
|
theFileToDelete = getFtpCommandArg("DELE", theClientData->theCommandReceived);
|
||||||
|
|
||||||
|
|
||||||
|
cleanDynamicStringDataType(&theResponse, 1);
|
||||||
|
cleanDynamicStringDataType(&deleFileName, 1);
|
||||||
|
|
||||||
|
if (theFileToDelete[0] == '/')
|
||||||
|
{
|
||||||
|
setDynamicStringDataType(&deleFileName, theFileToDelete, strlen(theFileToDelete));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setDynamicStringDataType(&deleFileName, theClientData->login.absolutePath.text, theClientData->login.absolutePath.textLen);
|
||||||
|
appendToDynamicStringDataType(&deleFileName, "/", 1);
|
||||||
|
appendToDynamicStringDataType(&deleFileName, theFileToDelete, strlen(theFileToDelete));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(theFileToDelete) > 0)
|
||||||
|
{
|
||||||
|
printf("\nThe file to delete is: %s", deleFileName.text);
|
||||||
|
returnStatus = remove(deleFileName.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
setDynamicStringDataType(&theResponse, "250 Deleted ", strlen("250 Deleted "));
|
||||||
|
appendToDynamicStringDataType(&theResponse, theFileToDelete, strlen(theFileToDelete));
|
||||||
|
appendToDynamicStringDataType(&theResponse, "\r\n", strlen("\r\n"));
|
||||||
|
|
||||||
|
write(theClientData->socketDescriptor, theResponse.text, theResponse.textLen);
|
||||||
|
cleanDynamicStringDataType(&theResponse, 0);
|
||||||
|
cleanDynamicStringDataType(&deleFileName, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int parseCommandRmd(clientDataType *theClientData)
|
int parseCommandRmd(clientDataType *theClientData)
|
||||||
{
|
{
|
||||||
int returnStatus = 0;
|
int returnStatus = 0;
|
||||||
@ -497,7 +576,7 @@ int parseCommandRmd(clientDataType *theClientData)
|
|||||||
|
|
||||||
if (strlen(theDirectoryFilename) > 0)
|
if (strlen(theDirectoryFilename) > 0)
|
||||||
{
|
{
|
||||||
printf("\nThe directory to make is: %s", mkdFileName.text);
|
printf("\nThe directory to delete is: %s", mkdFileName.text);
|
||||||
returnStatus = rmdir(mkdFileName.text);
|
returnStatus = rmdir(mkdFileName.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ int parseCommandPwd(clientDataType *theClientData);
|
|||||||
int parseCommandSyst(clientDataType *theClientData);
|
int parseCommandSyst(clientDataType *theClientData);
|
||||||
int parseCommandFeat(clientDataType *theClientData);
|
int parseCommandFeat(clientDataType *theClientData);
|
||||||
int parseCommandTypeI(clientDataType *theClientData);
|
int parseCommandTypeI(clientDataType *theClientData);
|
||||||
|
int parseCommandAbor(ftpDataType * data, int socketId);
|
||||||
int parseCommandPasv(ftpDataType * data, int socketId);
|
int parseCommandPasv(ftpDataType * data, int socketId);
|
||||||
int parseCommandList(ftpDataType * data, int socketId);
|
int parseCommandList(ftpDataType * data, int socketId);
|
||||||
int parseCommandRetr(ftpDataType * data, int socketId);
|
int parseCommandRetr(ftpDataType * data, int socketId);
|
||||||
@ -38,6 +39,7 @@ int parseCommandRmd(clientDataType *theClientData);
|
|||||||
int parseCommandStor(ftpDataType * data, int socketId);
|
int parseCommandStor(ftpDataType * data, int socketId);
|
||||||
int parseCommandCwd(clientDataType *theClientData);
|
int parseCommandCwd(clientDataType *theClientData);
|
||||||
int parseCommandCdup(clientDataType *theClientData);
|
int parseCommandCdup(clientDataType *theClientData);
|
||||||
|
int parseCommandDele(clientDataType *theClientData);
|
||||||
|
|
||||||
int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom);
|
int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom);
|
||||||
char *getFtpCommandArg(char * theCommand, char *theCommandString);
|
char *getFtpCommandArg(char * theCommand, char *theCommandString);
|
||||||
|
@ -236,6 +236,7 @@ void deleteListDataInfoVector(void *TheElementToDelete)
|
|||||||
void resetPasvData(passiveDataType *pasvData, int isInitialization)
|
void resetPasvData(passiveDataType *pasvData, int isInitialization)
|
||||||
{
|
{
|
||||||
pasvData->passivePort = 0;
|
pasvData->passivePort = 0;
|
||||||
|
pasvData->threadIsBusy = 0;
|
||||||
pasvData->passiveModeOn = 0;
|
pasvData->passiveModeOn = 0;
|
||||||
pasvData->passiveSocketIsConnected = 0;
|
pasvData->passiveSocketIsConnected = 0;
|
||||||
pasvData->commandIndex = 0;
|
pasvData->commandIndex = 0;
|
||||||
|
@ -65,6 +65,7 @@ struct passiveData
|
|||||||
char theFileNameToStor[CLIENT_COMMAND_STRING_SIZE];
|
char theFileNameToStor[CLIENT_COMMAND_STRING_SIZE];
|
||||||
int theFileNameToStorIndex;
|
int theFileNameToStorIndex;
|
||||||
unsigned long int retrRestartAtByte;
|
unsigned long int retrRestartAtByte;
|
||||||
|
int threadIsBusy;
|
||||||
|
|
||||||
/* The PASV thread will wait the signal before start */
|
/* The PASV thread will wait the signal before start */
|
||||||
pthread_mutex_t conditionMutex;
|
pthread_mutex_t conditionMutex;
|
||||||
|
19
ftpServer.c
19
ftpServer.c
@ -127,6 +127,9 @@ void *pasvThreadHandler(void * socketId)
|
|||||||
(strncmp(ftpData.clients[theSocketId].pasvData.theCommandReceived, "stor", strlen("stor")) == 0)) &&
|
(strncmp(ftpData.clients[theSocketId].pasvData.theCommandReceived, "stor", strlen("stor")) == 0)) &&
|
||||||
ftpData.clients[theSocketId].pasvData.theFileNameToStorIndex > 0)
|
ftpData.clients[theSocketId].pasvData.theFileNameToStorIndex > 0)
|
||||||
{
|
{
|
||||||
|
//Set the busy flag
|
||||||
|
ftpData.clients[theSocketId].pasvData.threadIsBusy = 1;
|
||||||
|
|
||||||
FILE *theStorFile;
|
FILE *theStorFile;
|
||||||
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
|
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
|
||||||
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
|
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
|
||||||
@ -146,8 +149,6 @@ void *pasvThreadHandler(void * socketId)
|
|||||||
|
|
||||||
printf("\nSaving new file to the server: %s", theFullFileName);
|
printf("\nSaving new file to the server: %s", theFullFileName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
strcpy(theResponse, "150 Accepted data connection\r\n");
|
strcpy(theResponse, "150 Accepted data connection\r\n");
|
||||||
write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
|
write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
|
||||||
|
|
||||||
@ -240,6 +241,9 @@ void *pasvThreadHandler(void * socketId)
|
|||||||
((strncmp(ftpData.clients[theSocketId].pasvData.theCommandReceived, "RETR", strlen("RETR")) == 0) ||
|
((strncmp(ftpData.clients[theSocketId].pasvData.theCommandReceived, "RETR", strlen("RETR")) == 0) ||
|
||||||
(strncmp(ftpData.clients[theSocketId].pasvData.theCommandReceived, "retr", strlen("retr")) == 0)))
|
(strncmp(ftpData.clients[theSocketId].pasvData.theCommandReceived, "retr", strlen("retr")) == 0)))
|
||||||
{
|
{
|
||||||
|
//Set the busy flag
|
||||||
|
ftpData.clients[theSocketId].pasvData.threadIsBusy = 1;
|
||||||
|
|
||||||
int theFileSize = 0;
|
int theFileSize = 0;
|
||||||
int writenSize = 0;
|
int writenSize = 0;
|
||||||
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
|
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
|
||||||
@ -683,13 +687,13 @@ static int processCommand(int processingElement)
|
|||||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "abor", strlen("abor")) == 0)
|
strncmp(ftpData.clients[processingElement].theCommandReceived, "abor", strlen("abor")) == 0)
|
||||||
{
|
{
|
||||||
printf("\nABOR command received");
|
printf("\nABOR command received");
|
||||||
//To implement
|
toReturn = parseCommandAbor(&ftpData, processingElement);
|
||||||
}
|
}
|
||||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "DELE", strlen("DELE")) == 0 ||
|
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "DELE", strlen("DELE")) == 0 ||
|
||||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "dele", strlen("dele")) == 0)
|
strncmp(ftpData.clients[processingElement].theCommandReceived, "dele", strlen("dele")) == 0)
|
||||||
{
|
{
|
||||||
printf("\nDELE command received");
|
printf("\nDELE command received");
|
||||||
//To implement
|
toReturn = parseCommandDele(&ftpData.clients[processingElement]);
|
||||||
}
|
}
|
||||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "MTDM", strlen("MTDM")) == 0 ||
|
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "MTDM", strlen("MTDM")) == 0 ||
|
||||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "mtdm", strlen("mtdm")) == 0)
|
strncmp(ftpData.clients[processingElement].theCommandReceived, "mtdm", strlen("mtdm")) == 0)
|
||||||
@ -726,18 +730,24 @@ static int processCommand(int processingElement)
|
|||||||
{
|
{
|
||||||
printf("\nRNFR command received");
|
printf("\nRNFR command received");
|
||||||
//To implement
|
//To implement
|
||||||
|
//350 RNFR accepted - file exists, ready for destination
|
||||||
|
//550 Sorry, but that file doesn't exist
|
||||||
}
|
}
|
||||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "RNTO", strlen("RNTO")) == 0 ||
|
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "RNTO", strlen("RNTO")) == 0 ||
|
||||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "rnto", strlen("rnto")) == 0)
|
strncmp(ftpData.clients[processingElement].theCommandReceived, "rnto", strlen("rnto")) == 0)
|
||||||
{
|
{
|
||||||
printf("\nRNTO command received");
|
printf("\nRNTO command received");
|
||||||
//To implement
|
//To implement
|
||||||
|
//503 Need RNFR before RNTO
|
||||||
|
//250 File successfully renamed or moved
|
||||||
}
|
}
|
||||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "SIZE", strlen("SIZE")) == 0 ||
|
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "SIZE", strlen("SIZE")) == 0 ||
|
||||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "size", strlen("size")) == 0)
|
strncmp(ftpData.clients[processingElement].theCommandReceived, "size", strlen("size")) == 0)
|
||||||
{
|
{
|
||||||
printf("\nSIZE command received");
|
printf("\nSIZE command received");
|
||||||
//To implement
|
//To implement
|
||||||
|
//213 71
|
||||||
|
//550 Can't check for file existence
|
||||||
}
|
}
|
||||||
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "APPE", strlen("APPE")) == 0 ||
|
else if(strncmp(ftpData.clients[processingElement].theCommandReceived, "APPE", strlen("APPE")) == 0 ||
|
||||||
strncmp(ftpData.clients[processingElement].theCommandReceived, "appe", strlen("appe")) == 0)
|
strncmp(ftpData.clients[processingElement].theCommandReceived, "appe", strlen("appe")) == 0)
|
||||||
@ -750,6 +760,7 @@ static int processCommand(int processingElement)
|
|||||||
{
|
{
|
||||||
printf("\nNOOP command received");
|
printf("\nNOOP command received");
|
||||||
//To implement
|
//To implement
|
||||||
|
//200 Zzz...
|
||||||
}
|
}
|
||||||
//REST COMMAND
|
//REST COMMAND
|
||||||
//REST 0
|
//REST 0
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
displayName="Important Files"
|
displayName="Important Files"
|
||||||
projectFiles="false"
|
projectFiles="false"
|
||||||
kind="IMPORTANT_FILES_FOLDER">
|
kind="IMPORTANT_FILES_FOLDER">
|
||||||
|
<itemPath>MakeSimple</itemPath>
|
||||||
<itemPath>Makefile</itemPath>
|
<itemPath>Makefile</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
|
@ -7,11 +7,12 @@
|
|||||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
<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">
|
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||||
<group>
|
<group>
|
||||||
<file>file:/home/ugo/NetBeansProjects/uFTP/library/fileManagement.c</file>
|
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpData.c</file>
|
||||||
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpCommandElaborate.c</file>
|
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpCommandElaborate.c</file>
|
||||||
<file>file:/home/ugo/NetBeansProjects/uFTP/library/logFunctions.c</file>
|
|
||||||
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpServer.c</file>
|
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpServer.c</file>
|
||||||
<file>file:/home/ugo/NetBeansProjects/uFTP/uFTP.c</file>
|
<file>file:/home/ugo/NetBeansProjects/uFTP/uFTP.c</file>
|
||||||
|
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpData.h</file>
|
||||||
|
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpCommandsElaborate.h</file>
|
||||||
</group>
|
</group>
|
||||||
</open-files>
|
</open-files>
|
||||||
</project-private>
|
</project-private>
|
||||||
|
Reference in New Issue
Block a user