tw0966.pp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. { %INTERACTIVE }
  2. { Source provided for Free Pascal Bug Report 966 }
  3. {$i-}
  4. {$ifdef linux}
  5. {$define has_sockets}
  6. {$endif linux}
  7. {$ifdef win32}
  8. {$define has_sockets}
  9. {$endif win32}
  10. {$ifdef has_sockets}
  11. uses
  12. {$ifdef linux}
  13. linux,
  14. {$else}
  15. crt,
  16. {$endif}
  17. Sockets;
  18. Var
  19. S : Longint ; Sin,Sout: Text;
  20. Temp, Temp2 : Char;
  21. i : longint;
  22. const
  23. isocket: TInetSockAddr= (
  24. Family:AF_INET;
  25. Port:$1500;
  26. Addr:((93*256+36)*256+161)*256+130);
  27. {*** ftp 130.161.36.93 i.e. ftp.freepascal.org }
  28. { FIXME: it would be much better to have the number
  29. through a name server but I don't know how to do this ! PM }
  30. procedure perror(const S: string);
  31. begin
  32. writeln(S,SocketError);
  33. halt(100) ;
  34. end;
  35. procedure read_to_eof;
  36. var
  37. temp2 : char;
  38. begin
  39. {$ifdef linux}
  40. while selecttext(sin,1)>0 do
  41. begin
  42. read(Sin,Temp2);
  43. write(Temp2);
  44. end;
  45. {$else}
  46. repeat until not eof(sin);
  47. while not eof(sin) do
  48. begin
  49. read(Sin,Temp2);
  50. write(Temp2);
  51. delay(1);
  52. end;
  53. {$endif}
  54. end;
  55. begin
  56. S:=Socket(AF_INET,SOCK_STREAM,0);
  57. if SocketError<>0 then Perror('Client : Socket : ');
  58. WriteLn('*1');
  59. if not Connect(s,isocket,sin,sout)then Perror('Client : Socket : ');
  60. WriteLn('*2');
  61. ReWrite(Sout); Reset(Sin);
  62. WriteLn('*3');
  63. read_to_eof;
  64. Writeln('Sending "USER anonymous#10"');
  65. Write(Sout,'USER anonymous'#10);
  66. read_to_eof;
  67. Writeln('Sending "PASS [email protected]#10"');
  68. Write(Sout,'PASS [email protected]'#10);
  69. read_to_eof;
  70. Writeln('Sending "QUIT#10"');
  71. Write(Sout,'QUIT'#10);
  72. read_to_eof;
  73. shutdown(s,2); close(sin); close(sout);
  74. {$else : not has_sockets}
  75. begin
  76. Writeln('No sockets unit for this target');
  77. {$endif has_sockets}
  78. end.