Use C-fu rather than silly conditionals and make some assumptions that make sending a file easier.
parent
52fc686908
commit
63d6decaad
2
README
2
README
|
@ -3,7 +3,7 @@ Andrew Coleman
|
||||||
CSC-4200
|
CSC-4200
|
||||||
|
|
||||||
To compile:
|
To compile:
|
||||||
gcc -o cftp -lm -Wall server.c client.c filesystem.c cftp.c
|
gcc -o cftp -Wall server.c client.c filesystem.c cftp.c
|
||||||
|
|
||||||
For explanation on running:
|
For explanation on running:
|
||||||
./cftp -h
|
./cftp -h
|
||||||
|
|
12
filesystem.c
12
filesystem.c
|
@ -7,7 +7,6 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include "cftp.h"
|
#include "cftp.h"
|
||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
|
@ -57,7 +56,7 @@ void send_file(int skt, const char *filename)
|
||||||
memset(errmsg, '\0', ERRMSGLEN);
|
memset(errmsg, '\0', ERRMSGLEN);
|
||||||
memset(cmd, '\0', CMDLEN);
|
memset(cmd, '\0', CMDLEN);
|
||||||
memset(arg, '\0', MSGLEN);
|
memset(arg, '\0', MSGLEN);
|
||||||
memset(msg, (unsigned char)0, MSGLEN);
|
memset(msg, '\0', MSGLEN);
|
||||||
|
|
||||||
/* file must exist */
|
/* file must exist */
|
||||||
if(!exist(filename))
|
if(!exist(filename))
|
||||||
|
@ -73,7 +72,7 @@ void send_file(int skt, const char *filename)
|
||||||
error("That file is inappropriately sized!");
|
error("That file is inappropriately sized!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
segments = ceil(MAXFILE / MSGLEN);
|
segments = MAXFILE / MSGLEN;
|
||||||
|
|
||||||
/* make a copy then figure out just the filename */
|
/* make a copy then figure out just the filename */
|
||||||
strcpy(msg, filename);
|
strcpy(msg, filename);
|
||||||
|
@ -94,7 +93,7 @@ void send_file(int skt, const char *filename)
|
||||||
error(errmsg);
|
error(errmsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(strcmp(cmd, "cts") != 0)
|
else if(strcmp(cmd, "cts"))
|
||||||
{
|
{
|
||||||
sprintf(errmsg, "ERROR invalid reponse from remote: %s", msg);
|
sprintf(errmsg, "ERROR invalid reponse from remote: %s", msg);
|
||||||
error(errmsg);
|
error(errmsg);
|
||||||
|
@ -111,10 +110,11 @@ void send_file(int skt, const char *filename)
|
||||||
for(cur_segment = 0; cur_segment < segments; cur_segment++)
|
for(cur_segment = 0; cur_segment < segments; cur_segment++)
|
||||||
{
|
{
|
||||||
fread(msg, MSGLEN, 1, infile);
|
fread(msg, MSGLEN, 1, infile);
|
||||||
sprintf(errmsg, "\rSending File: %.2f%%", floor(cur_segment / segments * 100.0));
|
sprintf(errmsg, "\rFilesystem: Sending file %.2f%%", (cur_segment / segments * 100.0));
|
||||||
debug("Filesystem", errmsg);
|
printf(errmsg);
|
||||||
send_message(skt, msg);
|
send_message(skt, msg);
|
||||||
}
|
}
|
||||||
|
debug("Filesystem", "File sent successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The MAXFILE size is calculated to be the largest integer in CMDLEN - 1
|
* The MAXFILE size is calculated to be the largest integer in CMDLEN - 1
|
||||||
* characters times MSGLEN.
|
* characters times MSGLEN. MAXFILE must be a multiple of MSGLEN.
|
||||||
*
|
*
|
||||||
* 9999 * 128 bytes = 1279872 bytes maximum
|
* 9999 * 128 bytes = 1279872 bytes maximum
|
||||||
*
|
*
|
||||||
|
|
Reference in New Issue