Skip to content

get command creates non-existent files #9

@GoldBinocle

Description

@GoldBinocle

How to reproduce

  1. Compile using make
  2. Start the server: ./bin/server/server_ftp.out
  3. Start the client: ./bin/client/client_ftp.out
  4. Type command on the client side
    4.1 First list the existing file in the project
CLIENT=> FTP Client started up. Attempting communication with server @ 127.0.0.1:8487...

        > ls
        FILE:   Makefile
        FILE:   TODO
        DIR:    .git
        FILE:   client_ftp_functions.c
        FILE:   server_ftp_functions.c
        DIR:    ..
        FILE:   client_ftp.h
        FILE:   commons.c
        FILE:   file_transfer_functions.c
        FILE:   server_ftp.h
        FILE:   commons.h
        FILE:   server_ftp.c
        DIR:    bin
        FILE:   README
        DIR:    .
        FILE:   .gitignore
        DIR:    obj
        FILE:   file_transfer_functions.h
        FILE:   .vimrc.custom.FTP
        FILE:   client_ftp.c

4.2 Then try to get a file that does not exist (file_not_exist)

        > get file_not_exist
        File found; processing
        1 data packet(s) received.
        0 byte(s) written.

4.3 List the file after the get command

        > ls
        FILE:   Makefile
        FILE:   TODO
        DIR:    .git
        FILE:   client_ftp_functions.c
        FILE:   file_not_exist
        FILE:   server_ftp_functions.c
        DIR:    ..
        FILE:   client_ftp.h
        FILE:   commons.c
        FILE:   file_transfer_functions.c
        FILE:   server_ftp.h
        FILE:   commons.h
        FILE:   server_ftp.c
        DIR:    bin
        FILE:   README
        DIR:    .
        FILE:   .gitignore
        DIR:    obj
        FILE:   file_transfer_functions.h
        FILE:   .vimrc.custom.FTP
        FILE:   client_ftp.c
        > 

We can see that file_not_exist is created.

Analysis

void command_get(struct packet* shp, struct packet* data, int sfd_client)
{
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.");
//printpacket(shp, HP);
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);
}
send_EOT(shp, data, sfd_client);
}

The command_get function should first check the existence of the file to transfer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions