1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| int upload_file (const SOCKET sock, FILE* file){
char ch [4] ; //on enverra les octets 4 par 4
printf ("{*} Uploading %s ...\n", str) ;
while (fgets (ch, 2, file) != NULL) { // tant qu'on peut lire dans le ficher
if (send (sock, &ch, 1, 0) == SOCKET_ERROR) { // s'il y a une erreur durant l'envoie
perror ("{-} Failed during the upload ...\n") ;
fclose (file) ;
return 0 ;
}
}
if (send (sock, "EOF", 4, 0) == SOCKET_ERROR) { // On envoie un EOF que le serveur n'écrira pas dans le fichier
perror ("{-} Failed while sending last char ...\n") ;
fclose (file) ;
return 0 ;
}
printf ("{*} Successfuly uploaded the file : %s ...\n", str) ;
fclose(file) ; //close the opened file
return 1 ;
} |