Reading a file and writing to a socket are two different operations. Winsock does not have an API to send a file directly.
As for reading a file, just make sure you open it in binary read mode if you use fopen, or just use the CreateFile and ReadFile Win32 API, and by default it will be binary.
You will usually read the file in chunks (for example, 10 KB at a time), and then send each of these fragments through a socket using send or WSASend . Once you are done, you can close the socket.
On the receiving side, read everything that is available on the socket until the socket is closed. When you read the data into the buffer, write the amount read into the file.
source
share