SHARE
TWEET

Untitled

a guest Jun 12th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. else if(strcmp(command[0], "get") == 0){
  2.        FILE *fp = fopen(command[1],"r");
  3.        int curr_pos;
  4.        if(fp==NULL){
  5.         send(client, "File Not Found", sizeof("File Not Found"), 0);
  6.         continue;
  7.         //fprintf(stderr, "Not Found");
  8.        }else{
  9.           unsigned char *filecontent;
  10.           fseek(fp,0,SEEK_END);
  11.           curr_pos = ftell(fp);
  12.           fseek(fp,0,SEEK_SET);
  13.           filecontent = malloc(curr_pos+1);
  14.           //bzero(filecontent, 256);
  15.           int nread = fread(filecontent,1,curr_pos,fp);
  16.          
  17.           if(nread>0){
  18.             printf("sending\n");
  19.             send(client,filecontent,nread,0);
  20.           }
  21.  
  22.           if(nread<curr_pos){
  23.             if(feof(fp)){
  24.               send(client,"End of file",sizeof("End of file"),0);
  25.             }
  26.             if(ferror(fp)){
  27.               printf("Error");
  28.             }
  29.           }
  30.        }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top