Skip to content

Commit

Permalink
get implemented but it is not working for non-text-only files. commit…
Browse files Browse the repository at this point in the history
… before debugging.
  • Loading branch information
rovinbhandari committed Mar 9, 2012
1 parent a7b300a commit 29eadbc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
13 changes: 11 additions & 2 deletions client_ftp_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,16 @@ void command_get(struct packet* chp, struct packet* data, int sfd_client, char*
data = htonp(chp);
if((x = send(sfd_client, data, size_packet, 0)) != size_packet)
er("send()", x);
receive_file(chp, data, sfd_client, f);
fclose(f);
if((x = recv(sfd_client, data, size_packet, 0)) <= 0)
er("recv()", x);
chp = ntohp(data);
if(chp->type == INFO && chp->comid == GET && strlen(chp->buffer))
{
printf("\t%s\n", chp->buffer);
receive_file(chp, data, sfd_client, f);
fclose(f);
}
else
fprintf(stderr, "Error getting remote file.\n");
}

16 changes: 10 additions & 6 deletions file_transfer_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@ void send_TERM(struct packet* hp, struct packet* data, int sfd)
void send_file(struct packet* hp, struct packet* data, int sfd, FILE* f)
{
int x;
strcpy(hp->buffer, "test");
hp->type = DATA;
data = htonp(hp);
if((x = send(sfd, data, size_packet, 0)) != size_packet)
er("send()", x);
send_EOT(hp, data, sfd);
while(!feof(f))
{
fread(hp->buffer, 1, LENBUFFER, f);
data = htonp(hp);
if((x = send(sfd, data, size_packet, 0)) != size_packet)
er("send()", x);
}
}

void receive_file(struct packet* hp, struct packet* data, int sfd, FILE* f)
{
int x;
if((x = recv(sfd, data, size_packet, 0)) <= 0)
er("recv()", x);
hp = ntohp(data);
while(hp->type == DATA)
{
fwrite(hp->buffer, 1, strlen(hp->buffer), f);
Expand Down
9 changes: 7 additions & 2 deletions server_ftp_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,20 @@ void command_ls(struct packet* shp, struct packet* data, int sfd_client, char* l

void command_get(struct packet* shp, struct packet* data, int sfd_client)
{
FILE* f = fopen(shp->buffer, "rb");
int x;
FILE* f = fopen(shp->buffer, "rb"); // Yo!
shp->type = INFO;
shp->comid = GET;
strcpy(shp->buffer, f ? "File found; processing" : "Error opening file.");
data = htonp(shp);
if((x = send(sfd_client, data, size_packet, 0)) != size_packet)
er("send()", x);
if(f)
{
shp->type = DATA;
send_file(shp, data, sfd_client, f);
fclose(f);
fclose(f);
}
send_EOT(shp, data, sfd_client);
}

0 comments on commit 29eadbc

Please sign in to comment.