I'm developing a client/server program in C. The server send to a client a txt file, but the name is like corrupt. The content is good, only the name is not good.
Can someone tell me why? Thank you!
This is the code who send the file:
fd = open(appoggio1, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "unable to open '%s': %s\n", appoggio1, strerror(errno));
exit(1);
}
while ((nread = read(fd, buffer2, sizeof(buffer2))) > 0)
{
write(servers_fd, buffer2, nread);
read(servers_fd,buffer2,sizeof(char));
}
printf("Trasmissione completata con successo\n\n");
write(servers_fd,fine,strlen(fine));
read(servers_fd,fine,strlen(fine));
close(fd);
This is the code who receive the file:
fd = open(nomefile, O_CREAT | O_WRONLY, 0755);
if (fd < 0)
{
fprintf(stderr, "errore open(): %s\n", strerror(errno));
exit(errno);
}
while ((nread = read(conn_fd, buffer, sizeof(buffer))) > 0)
{
if(!strncmp(buffer,fine,7))
break;
write(fd, buffer, nread);
write(conn_fd,buffer,sizeof(char));
}
write(conn_fd,fine,strlen(fine));
}
nomefile..?