severftp.c 772 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include<stdio.h>
  2. #include<unistd.h>
  3. #include<sys/socket.h>
  4. #include<sys/types.h>
  5. #include<netinet/in.h>
  6. #include<string.h>
  7. #include<stdlib.h>
  8. int main()
  9. {
  10. int sd,port,i;
  11. char msg[80];
  12. FILE *fp;
  13. struct sockaddr_in cli;
  14. sd=socket(AF_INET,SOCK_STREAM,0);
  15. bzero(&cli,sizeof(cli));
  16. printf("enter the port no");
  17. scanf("%d",&port);
  18. cli.sin_port=port;
  19. cli.sin_addr.s_addr=inet_addr("127.0.0.1");
  20. cli.sin_family=AF_INET;
  21. connect(sd,(struct sockaddr*)&cli,sizeof(cli));
  22. // printf("\nenter the command\n");
  23. // scanf("%s",msg);
  24. // write(sd,msg,strlen(msg));
  25. // system(msg);
  26. // read(sd,msg,10);
  27. // printf("%s",msg);
  28. memset(msg,'\0',sizeof(msg));
  29. fp=fopen("out.txt","a+");
  30. read(sd,msg,10);
  31. for(i=0;i<strlen(msg);i++)
  32. {
  33. fputc(msg[i],fp);
  34. }
  35. fclose(fp);
  36. return 0;
  37. }