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


    char* rbuffer;          //will save file content here

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

    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];, size);       //write file to buffer

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

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


    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.