42-archive/ftp/srcs/serv_do_put.c
2017-07-25 18:20:34 +02:00

23 lines
451 B
C

#include "ft_p.h"
int serv_do_put(int sock)
{
char fname[MAXLINE];
int rep;
int fd;
ft_bzero(&fname, MAXLINE);
rep = htons(TRANSFER_START);
if (read(sock, fname, MAXLINE) < 0)
rep = htons(ABORT);
else if ((fd = open_new(fname, O_WRONLY | O_TRUNC | O_APPEND)) < 0)
rep = htons(ABORT);
write(sock, (char*)&rep, sizeof(rep));
if (rep != htons(TRANSFER_START))
return (CMD_FAIL);
net_get_large(sock, fd);
return (CMD_SUCCESS);
}