STOR command preliminary implementation ok

This commit is contained in:
Ugo Cirmignani
2018-01-06 19:29:07 +01:00
parent d0593cbdbb
commit a9cd5e1802
6 changed files with 30 additions and 17 deletions

Binary file not shown.

Binary file not shown.

View File

@ -272,12 +272,16 @@ int parseCommandStor(ftpDataType * data, int socketId)
}
}
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);
return 1;
}
int parseCommandCwd(clientDataType *theClientData)

View File

@ -127,18 +127,26 @@ void *pasvThreadHandler(void * socketId)
(strncmp(ftpData.clients[theSocketId].pasvData.theCommandReceived, "stor", strlen("stor")) == 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);
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);
if (theAbsoluteFileNamePath[strlen(theAbsoluteFileNamePath)-1] != '/')
strcat(theAbsoluteFileNamePath, "/");
strcat(theAbsoluteFileNamePath, ftpData.clients[theSocketId].pasvData.theFileNameToStor);
strcpy(theResponse, "150 Accepted data connection\r\n");
write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
@ -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));

View File

@ -7,7 +7,11 @@
<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>
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpCommandsElaborate.h</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/library/fileManagement.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/uFTP.c</file>
</group>
</open-files>
</project-private>