So if you want to send a text file to some you would use:

Client:

    char* rbuffer;          //will save file content here


ifstream file;
file.open(filepath, ios::in | ios::binary | ios::ate);      //open file

if(file.is_open()){
    file.seekg(0, ios::end);
    size = file.tellg();    //file size!

    cout << "The file size is " << size << " Bytes" << endl;

    file.seekg(0, ios::beg);        //sets location back to beginning of file

    rbuffer = new char[size];
    file.read(rbuffer, size);       //write file to buffer

    clock_t ustart, uend;           //timer
    ustart=clock();
    int j = send(sock, rbuffer, size, NULL);    //send file to server

    if (j == -1){
        cout << "Error uploading file to server :(" << endl;
    }

Server:

    char* rbuffer;
    rbuffer = new char[5000]; //will write message to this buffer

    clock_t ustart, uend;
    ustart = clock();
    int k = recv(client_socket, rbuffer, sizeof(rbuffer), NULL);
    if (k < 0){
        cout << "Error uploading file" << endl;
    }
    cout << "File is being uploaded..." << endl;

    cout << "File received!" << endl;

But how can I send a .exe file over the internet?

The type of file is irrelevant if you're treating it as a sequence of bytes. As long as you don't lose any packets in the transfer, the .exe will be reconstructed correctly and will run on a matching OS.

May I ask why you want to send an executable over the internet? I sounds like your trying to make somesort of virus. Which would be against forum rules.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.