diff --git a/build/Debug/GNU-Linux/ftpCommandElaborate.o b/build/Debug/GNU-Linux/ftpCommandElaborate.o index c703aa2..b07e031 100644 Binary files a/build/Debug/GNU-Linux/ftpCommandElaborate.o and b/build/Debug/GNU-Linux/ftpCommandElaborate.o differ diff --git a/build/Debug/GNU-Linux/ftpServer.o b/build/Debug/GNU-Linux/ftpServer.o index a41a1f9..96cdac4 100644 Binary files a/build/Debug/GNU-Linux/ftpServer.o and b/build/Debug/GNU-Linux/ftpServer.o differ diff --git a/dist/Debug/GNU-Linux/uftp b/dist/Debug/GNU-Linux/uftp index 8abb718..ba11268 100755 Binary files a/dist/Debug/GNU-Linux/uftp and b/dist/Debug/GNU-Linux/uftp differ diff --git a/ftpCommandElaborate.c b/ftpCommandElaborate.c index 0ac986a..89341a5 100644 --- a/ftpCommandElaborate.c +++ b/ftpCommandElaborate.c @@ -271,13 +271,17 @@ int parseCommandStor(ftpDataType * data, int socketId) data->clients[socketId].pasvData.theFileNameToStor[data->clients[socketId].pasvData.theFileNameToStorIndex++] = data->clients[socketId].theCommandReceived[i]; } } + + printf("data->clients[%d].pasvData.theFileNameToStor = %s", socketId, data->clients[socketId].pasvData.theFileNameToStor); memset(data->clients[socketId].pasvData.theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE); strcpy(data->clients[socketId].pasvData.theCommandReceived, data->clients[socketId].theCommandReceived); data->clients[socketId].pasvData.commandReceived = 1; - return 1; + pthread_mutex_unlock(&data->clients[socketId].pasvData.conditionMutex); - pthread_cond_signal(&data->clients[socketId].pasvData.conditionVariable); + pthread_cond_signal(&data->clients[socketId].pasvData.conditionVariable); + + return 1; } int parseCommandCwd(clientDataType *theClientData) diff --git a/ftpServer.c b/ftpServer.c index 0973ba8..7b74345 100644 --- a/ftpServer.c +++ b/ftpServer.c @@ -125,25 +125,33 @@ void *pasvThreadHandler(void * socketId) if (ftpData.clients[theSocketId].pasvData.commandReceived == 1 && ((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) { + FILE *theStorFile; char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER]; memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER); - char theAbsoluteFileNamePath[FTP_COMMAND_ELABORATE_CHAR_BUFFER]; memset(theAbsoluteFileNamePath, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER); - - //strcpy(theAbsoluteFileNamePath, ftpData.clients[theSocketId].login.absolutePath); - if (theAbsoluteFileNamePath[strlen(theAbsoluteFileNamePath)-1] != '/') - strcat(theAbsoluteFileNamePath, "/"); + char *theFullFileName; + theFullFileName = (char *) malloc(ftpData.clients[theSocketId].login.absolutePath.textLen+1); + strcpy(theFullFileName, ftpData.clients[theSocketId].login.absolutePath.text); + if (theFullFileName[strlen(theAbsoluteFileNamePath)-1] != '/') + FILE_AppendToString(&theFullFileName, "/"); + + FILE_AppendToString(&theFullFileName, ftpData.clients[theSocketId].pasvData.theFileNameToStor); + + + theStorFile = fopen(theFullFileName, "wb"); + + printf("\nSaving new file to the server: %s", theFullFileName); + - strcat(theAbsoluteFileNamePath, ftpData.clients[theSocketId].pasvData.theFileNameToStor); strcpy(theResponse, "150 Accepted data connection\r\n"); write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse)); - + while(1) { if ((ftpData.clients[theSocketId].pasvData.bufferIndex = read(ftpData.clients[theSocketId].pasvData.passiveSocketConnection, ftpData.clients[theSocketId].pasvData.buffer, CLIENT_BUFFER_STRING_SIZE)) == 0) @@ -154,15 +162,12 @@ void *pasvThreadHandler(void * socketId) if (ftpData.clients[theSocketId].pasvData.bufferIndex > 0) { - int i = 0; - for (i = 0; i < ftpData.clients[theSocketId].pasvData.bufferIndex; i++) - { - ; - } + fwrite(ftpData.clients[theSocketId].pasvData.buffer, ftpData.clients[theSocketId].pasvData.bufferIndex, 1, theStorFile); usleep(100); } } - + close(theStorFile); + free(theFullFileName); memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER); sprintf(theResponse, "226 file stor ok\r\n"); write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse)); diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 029e357..d3f4e55 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -7,7 +7,11 @@ - file:/home/ugo/NetBeansProjects/uFTP/ftpCommandsElaborate.h + file:/home/ugo/NetBeansProjects/uFTP/library/fileManagement.c + file:/home/ugo/NetBeansProjects/uFTP/ftpCommandElaborate.c + file:/home/ugo/NetBeansProjects/uFTP/library/logFunctions.c + file:/home/ugo/NetBeansProjects/uFTP/ftpServer.c + file:/home/ugo/NetBeansProjects/uFTP/uFTP.c