mirror of
https://github.com/kingk85/uFTP.git
synced 2025-07-17 09:16:11 +03:00
STOR command preliminary implementation ok
This commit is contained in:
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.
@ -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];
|
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);
|
memset(data->clients[socketId].pasvData.theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE);
|
||||||
strcpy(data->clients[socketId].pasvData.theCommandReceived, data->clients[socketId].theCommandReceived);
|
strcpy(data->clients[socketId].pasvData.theCommandReceived, data->clients[socketId].theCommandReceived);
|
||||||
data->clients[socketId].pasvData.commandReceived = 1;
|
data->clients[socketId].pasvData.commandReceived = 1;
|
||||||
return 1;
|
|
||||||
pthread_mutex_unlock(&data->clients[socketId].pasvData.conditionMutex);
|
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)
|
int parseCommandCwd(clientDataType *theClientData)
|
||||||
|
33
ftpServer.c
33
ftpServer.c
@ -125,25 +125,33 @@ void *pasvThreadHandler(void * socketId)
|
|||||||
if (ftpData.clients[theSocketId].pasvData.commandReceived == 1 &&
|
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) ||
|
||||||
(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];
|
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
|
||||||
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
|
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
|
||||||
|
|
||||||
char theAbsoluteFileNamePath[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
|
char theAbsoluteFileNamePath[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
|
||||||
memset(theAbsoluteFileNamePath, 0, 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] != '/')
|
char *theFullFileName;
|
||||||
strcat(theAbsoluteFileNamePath, "/");
|
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");
|
strcpy(theResponse, "150 Accepted data connection\r\n");
|
||||||
write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
|
write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
|
||||||
|
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
if ((ftpData.clients[theSocketId].pasvData.bufferIndex = read(ftpData.clients[theSocketId].pasvData.passiveSocketConnection, ftpData.clients[theSocketId].pasvData.buffer, CLIENT_BUFFER_STRING_SIZE)) == 0)
|
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)
|
if (ftpData.clients[theSocketId].pasvData.bufferIndex > 0)
|
||||||
{
|
{
|
||||||
int i = 0;
|
fwrite(ftpData.clients[theSocketId].pasvData.buffer, ftpData.clients[theSocketId].pasvData.bufferIndex, 1, theStorFile);
|
||||||
for (i = 0; i < ftpData.clients[theSocketId].pasvData.bufferIndex; i++)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
usleep(100);
|
usleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(theStorFile);
|
||||||
|
free(theFullFileName);
|
||||||
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
|
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
|
||||||
sprintf(theResponse, "226 file stor ok\r\n");
|
sprintf(theResponse, "226 file stor ok\r\n");
|
||||||
write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
|
write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
|
||||||
|
@ -7,7 +7,11 @@
|
|||||||
<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/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>
|
</group>
|
||||||
</open-files>
|
</open-files>
|
||||||
</project-private>
|
</project-private>
|
||||||
|
Reference in New Issue
Block a user