while ((len = fread(Buffer,1,1024, fs)) > 0)
{
if((resultEnviar = send(ClientSocket,Buffer,1024,0)) < 0)
One of your issues is that you always send 1024 bytes of the buffer even if you fread
fewer bytes. (Note that 1348656 rounded up to the nearest multiple of 1024 is 1349632.)
So, on the write side you want something like:
while ((len = fread(Buffer,1,1024, fs)) > 0)
{
if((resultEnviar = send(ClientSocket,Buffer,len,0)) < 0)
and on the read side you want something like:
while((fr_block_sz = recv(sock, Buffer2, 1024, 0)) >= 0)
{
// ...
int write_sz = fwrite(Buffer2, 1, fr_block_sz, fp);
Your initial send
is also problematic as you always send 1024 bytes with no check that this is the actual length of what is returned by c_str
.