How to reproduce
- Compile using
make
- Start the server:
./bin/server/server_ftp.out
- Start the client:
./bin/client/client_ftp.out
- 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.
How to reproduce
make./bin/server/server_ftp.out./bin/client/client_ftp.out4.1 First list the existing file in the project
4.2 Then try to get a file that does not exist (
file_not_exist)4.3 List the file after the
getcommandWe can see that
file_not_existis created.Analysis
FTP/server_ftp_functions.c
Lines 51 to 69 in 96c1a35
The
command_getfunction should first check the existence of the file to transfer.