C++: how to transfer files to netcat listener?

179 Views Asked by At

I'm working on an IRC server using c++, and I want to add files transfer to my server, but I don't know how to create the file in the user's host. I can read the file and send the bytes to netcat, but netcat will receive bytes only. How do I make netcat create a new file in the user's machine?

void    _fileTransfer(char *filepath, int senderFd)
{
    FILE*    fd = fopen(filepath, "rb");
    if (fd == NULL)
        return ;
    char    buffer[256];
    int    bytes_read;
    int    sock = clientfd;
    while (!feof(fd)) {
        if ((bytes_read = fread(&buffer, 1, 255, fd)) > 0)
            send(sock, buffer, bytes_read, 0);
        else
            break;
    }
    fclose(fd);
}

0

There are 0 best solutions below