norme
This commit is contained in:
parent
e9802e5c00
commit
e7643cc6c7
6 changed files with 32 additions and 61 deletions
|
|
@ -47,6 +47,7 @@ client/client.c\
|
|||
client/console_msg.c\
|
||||
client/crlf.c\
|
||||
client/dconn.c\
|
||||
client/ftp_crlf.c\
|
||||
server/cmd_cwd.c\
|
||||
server/cmd_dele.c\
|
||||
server/cmd_epsv.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/11/10 16:20:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/11/15 13:22:33 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/11/20 13:01:26 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,23 +23,36 @@ static char *fname(char *path)
|
|||
return (path);
|
||||
}
|
||||
|
||||
int cli_put(t_ftp *ftp, char **av)
|
||||
int fdata(char **av, struct stat *buf, char **file)
|
||||
{
|
||||
struct stat buf;
|
||||
char *file;
|
||||
int fd;
|
||||
|
||||
if (!av[1] || av[2])
|
||||
return (console_msg(-1, "usage: put <filename>"));
|
||||
if ((fd = open(av[1], O_RDONLY)) < 0 || fstat(fd, &buf) < 0)
|
||||
if ((fd = open(av[1], O_RDONLY)) < 0 || fstat(fd, buf) < 0)
|
||||
return (console_msg(-1, "no such file or directory"));
|
||||
if (buf->st_size == 0)
|
||||
{
|
||||
console_msg(0, "no such file or directory");
|
||||
close(fd);
|
||||
return (0);
|
||||
}
|
||||
if ((*file = mmap(NULL, buf->st_size, PROT_READ,
|
||||
MAP_PRIVATE, fd, 0)) == MAP_FAILED)
|
||||
{
|
||||
close(fd);
|
||||
return (-1);
|
||||
}
|
||||
if (!buf.st_size || (file = mmap(NULL, buf.st_size, PROT_READ,
|
||||
MAP_PRIVATE, fd, 0)) == MAP_FAILED)
|
||||
return (close(fd));
|
||||
close(fd);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int cli_put(t_ftp *ftp, char **av)
|
||||
{
|
||||
struct stat buf;
|
||||
char *file;
|
||||
|
||||
if (fdata(av, &buf, &file) != 0)
|
||||
return (-1);
|
||||
if (dconn_init(ftp) < 0)
|
||||
return (munmap(file, buf.st_size));
|
||||
FTP_CMD(ftp, "STOR %s", fname(av[1]));
|
||||
|
|
@ -49,7 +62,7 @@ int cli_put(t_ftp *ftp, char **av)
|
|||
return (munmap(file, buf.st_size));
|
||||
}
|
||||
console_msg(0, "upload in progess, please wait... (%i bytes)", buf.st_size);
|
||||
if (send(ftp->d_sock, file, buf.st_size, 0) < 0)
|
||||
if (buf.st_size && send(ftp->d_sock, file, buf.st_size, 0) < 0)
|
||||
console_msg(0, "upload FAIL");
|
||||
else
|
||||
console_msg(0, "upload SUCCESS");
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/10/08 12:05:23 by jhalford #+# #+# */
|
||||
/* Updated: 2017/11/15 13:00:38 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/11/20 13:01:37 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/11/08 19:52:07 by jhalford #+# #+# */
|
||||
/* Updated: 2017/11/15 13:26:43 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/11/20 13:00:14 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -85,46 +85,3 @@ int ftp_sendraw(int sock, char *file, off_t size)
|
|||
console_msg(1, "---> rawsend done size %zu", size);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
int ftp_send(int sock, char *msg, ...)
|
||||
{
|
||||
int err;
|
||||
char *crlf_tmp;
|
||||
char *crlf_msg;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, msg);
|
||||
ft_vasprintf(&crlf_tmp, msg, ap);
|
||||
console_msg(1, "---> %s", crlf_tmp);
|
||||
crlf_msg = ft_strjoin(crlf_tmp, "\r\n");
|
||||
if ((err = send(sock, crlf_msg, ft_strlen(crlf_msg), 0)) < 0)
|
||||
{
|
||||
return (err);
|
||||
}
|
||||
ft_strdel(&crlf_tmp);
|
||||
ft_strdel(&crlf_msg);
|
||||
return (ft_atoi(msg));
|
||||
}
|
||||
|
||||
int ftp_msg(t_ftp *ftp, char **msg)
|
||||
{
|
||||
int code;
|
||||
|
||||
if (ftp_recv(ftp->cmd_sock, msg) < 0)
|
||||
return (-1);
|
||||
code = ft_atoi(*msg);
|
||||
console_msg(0, "<--- %s (%i)", *msg, code);
|
||||
return (code);
|
||||
}
|
||||
|
||||
int ftp_code(t_ftp *ftp)
|
||||
{
|
||||
char *msg;
|
||||
int code;
|
||||
|
||||
if ((code = ftp_msg(ftp, &msg)) < 0)
|
||||
return (-1);
|
||||
ft_strdel(&msg);
|
||||
return (code);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/11/02 14:20:46 by jhalford #+# #+# */
|
||||
/* Updated: 2017/11/12 18:28:35 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/11/20 13:00:37 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/10/08 12:05:23 by jhalford #+# #+# */
|
||||
/* Updated: 2017/11/15 13:28:07 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/11/20 13:01:31 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue