home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume41 / libftp / part05 < prev    next >
Encoding:
Text File  |  1993-12-14  |  42.3 KB  |  1,593 lines

  1. Newsgroups: comp.sources.misc
  2. From: orel@oea.ihep.su (Oleg Orel)
  3. Subject: v41i038:  libftp - A C library interface for the FTP protocol, v1.2, Part05/05
  4. Message-ID: <1993Dec14.154930.25991@sparky.sterling.com>
  5. X-Md4-Signature: bd84091d33a5414e5c2be76707878074
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Tue, 14 Dec 1993 15:49:30 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: orel@oea.ihep.su (Oleg Orel)
  12. Posting-number: Volume 41, Issue 38
  13. Archive-name: libftp/part05
  14. Environment: UNIX
  15. Supersedes: libftp: Volume 38, Issue 52
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  libftp/FtpBye.c libftp/FtpClose.c libftp/FtpCommand.c
  22. #   libftp/FtpConnect.c libftp/FtpDebug.c libftp/FtpFopen.c
  23. #   libftp/FtpGetMessage.c libftp/FtpGetString.c libftp/FtpGood.c
  24. #   libftp/FtpInitMessage.c libftp/FtpLibrary.h libftp/FtpLogin.c
  25. #   libftp/FtpMessage.c libftp/FtpMove.c libftp/FtpNumber.c
  26. #   libftp/FtpOpenDir.c libftp/FtpPort.c libftp/FtpPwd.c
  27. #   libftp/FtpRead.c libftp/FtpRetrTimeout.c libftp/FtpSendMessage.c
  28. #   libftp/FtpStorTimeout.c libftp/FtpType.c libftp/FtpWrite.c
  29. #   libftp/Makefile libftp/examples/fcp.c libftp/examples/get.c
  30. #   libftp/utils/Makefile
  31. # Wrapped by kent@sparky on Tue Dec 14 09:21:00 1993
  32. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  33. echo If this archive is complete, you will see the following message:
  34. echo '          "shar: End of archive 5 (of 5)."'
  35. if test -f 'libftp/FtpBye.c' -a "${1}" != "-c" ; then 
  36.   echo shar: Will not clobber existing file \"'libftp/FtpBye.c'\"
  37. else
  38.   echo shar: Extracting \"'libftp/FtpBye.c'\" \(730 characters\)
  39.   sed "s/^X//" >'libftp/FtpBye.c' <<'END_OF_FILE'
  40. X/*
  41. X              Library for ftpd clients.(libftp)
  42. X            Copyright by Oleg Orel
  43. X             All rights reserved.
  44. X            
  45. XThis  library is desined  for  free,  non-commercial  software  creation. 
  46. XIt is changeable and can be improved. The author would greatly appreciate 
  47. Xany  advises, new  components  and  patches  of  the  existing  programs.
  48. XCommercial  usage is  also  possible  with  participation of it's author.
  49. X
  50. X
  51. X
  52. X*/
  53. X
  54. X#include "FtpLibrary.h"
  55. X
  56. XSTATUS FtpBye(FTP *sock)
  57. X{
  58. X  String S1;
  59. X  int i;
  60. X  
  61. X  if ( FtpSendMessage(sock,"QUIT") == QUIT )
  62. X    return EXIT(sock,QUIT);
  63. X
  64. X  if ( (i=FtpGetMessage(sock,S1)) == QUIT )
  65. X    return EXIT(sock,QUIT);
  66. X
  67. X  if ( i != 221 )
  68. X    return EXIT(sock,-i);
  69. X
  70. X  close(sock->sock);
  71. X  free(sock);
  72. X  return 0;
  73. X}
  74. X      
  75. END_OF_FILE
  76.   if test 730 -ne `wc -c <'libftp/FtpBye.c'`; then
  77.     echo shar: \"'libftp/FtpBye.c'\" unpacked with wrong size!
  78.   fi
  79.   # end of 'libftp/FtpBye.c'
  80. fi
  81. if test -f 'libftp/FtpClose.c' -a "${1}" != "-c" ; then 
  82.   echo shar: Will not clobber existing file \"'libftp/FtpClose.c'\"
  83. else
  84.   echo shar: Extracting \"'libftp/FtpClose.c'\" \(644 characters\)
  85.   sed "s/^X//" >'libftp/FtpClose.c' <<'END_OF_FILE'
  86. X/*
  87. X              Library for ftpd clients.(libftp)
  88. X            Copyright by Oleg Orel
  89. X             All rights reserved.
  90. X            
  91. XThis  library is desined  for  free,  non-commercial  software  creation. 
  92. XIt is changeable and can be improved. The author would greatly appreciate 
  93. Xany  advises, new  components  and  patches  of  the  existing  programs.
  94. XCommercial  usage is  also  possible  with  participation of it's author.
  95. X
  96. X
  97. X
  98. X*/
  99. X
  100. X#include "FtpLibrary.h"
  101. X
  102. XSTATUS FtpClose(FTP *sock)
  103. X{
  104. X  int i;
  105. X  String S1;
  106. X  
  107. X  fclose(sock->data);
  108. X
  109. X  if ((i=FtpGetMessage(sock,S1))==QUIT)
  110. X    return EXIT(sock,QUIT);
  111. X  if ( i != 226 )
  112. X    return EXIT(sock,-i);
  113. X  return EXIT(sock,i);
  114. X}
  115. END_OF_FILE
  116.   if test 644 -ne `wc -c <'libftp/FtpClose.c'`; then
  117.     echo shar: \"'libftp/FtpClose.c'\" unpacked with wrong size!
  118.   fi
  119.   # end of 'libftp/FtpClose.c'
  120. fi
  121. if test -f 'libftp/FtpCommand.c' -a "${1}" != "-c" ; then 
  122.   echo shar: Will not clobber existing file \"'libftp/FtpCommand.c'\"
  123. else
  124.   echo shar: Extracting \"'libftp/FtpCommand.c'\" \(1198 characters\)
  125.   sed "s/^X//" >'libftp/FtpCommand.c' <<'END_OF_FILE'
  126. X/*
  127. X              Library for ftpd clients.(libftp)
  128. X            Copyright by Oleg Orel
  129. X             All rights reserved.
  130. X            
  131. XThis  library is desined  for  free,  non-commercial  software  creation. 
  132. XIt is changeable and can be improved. The author would greatly appreciate 
  133. Xany  advises, new  components  and  patches  of  the  existing  programs.
  134. XCommercial  usage is  also  possible  with  participation of it's author.
  135. X
  136. X
  137. X
  138. X*/
  139. X
  140. X#include "FtpLibrary.h"
  141. X
  142. X#include <varargs.h>
  143. X
  144. XSTATUS FtpCommand(va_alist)
  145. X     va_dcl
  146. X{
  147. X  FTP *con;
  148. X  char *command, *param;
  149. X  int Answer[MAX_ANSWERS];
  150. X  va_list args;
  151. X  String S1;
  152. X  int i,counter=0;
  153. X  
  154. X  va_start(args);
  155. X
  156. X  con = va_arg(args,FTP *);
  157. X  command = va_arg(args,char *);
  158. X  param = va_arg(args, char *);
  159. X
  160. X  while ( 1 )
  161. X    {
  162. X      if (counter == MAX_ANSWERS)
  163. X    return EXIT(con,QUIT);
  164. X      Answer[counter] = va_arg(args,int);
  165. X      if (Answer[counter] == EOF ) break;
  166. X      counter++;
  167. X    }
  168. X
  169. X  va_end(args);
  170. X  
  171. X  
  172. X  sprintf(S1,command,param);
  173. X
  174. X  if ( FtpSendMessage(con,S1) == QUIT )
  175. X    return EXIT(con,QUIT);
  176. X  
  177. X  if  ( (i=FtpGetMessage(con,S1)) == QUIT )
  178. X    return EXIT(con,QUIT);
  179. X  
  180. X  if ( ! FtpGood1 ( i , Answer ))
  181. X    return EXIT(con,-i);
  182. X
  183. X  return EXIT(con,i);
  184. X}
  185. X  
  186. X  
  187. X   
  188. END_OF_FILE
  189.   if test 1198 -ne `wc -c <'libftp/FtpCommand.c'`; then
  190.     echo shar: \"'libftp/FtpCommand.c'\" unpacked with wrong size!
  191.   fi
  192.   # end of 'libftp/FtpCommand.c'
  193. fi
  194. if test -f 'libftp/FtpConnect.c' -a "${1}" != "-c" ; then 
  195.   echo shar: Will not clobber existing file \"'libftp/FtpConnect.c'\"
  196. else
  197.   echo shar: Extracting \"'libftp/FtpConnect.c'\" \(1841 characters\)
  198.   sed "s/^X//" >'libftp/FtpConnect.c' <<'END_OF_FILE'
  199. X/*
  200. X              Library for ftpd clients.(libftp)
  201. X            Copyright by Oleg Orel
  202. X             All rights reserved.
  203. X            
  204. XThis  library is desined  for  free,  non-commercial  software  creation. 
  205. XIt is changeable and can be improved. The author would greatly appreciate 
  206. Xany  advises, new  components  and  patches  of  the  existing  programs.
  207. XCommercial  usage is  also  possible  with  participation of it's author.
  208. X
  209. X
  210. X
  211. X*/
  212. X
  213. X#include "FtpLibrary.h"
  214. X
  215. XSTATUS FtpConnect(FTP **con,char * hostname)
  216. X{
  217. X  struct sockaddr_in unit;
  218. X  register struct hostent *host;
  219. X  register struct servent *service;
  220. X  register int sock;
  221. X  String S1;
  222. X  STATUS x;
  223. X  
  224. X  *con = ( FTP * ) malloc ( sizeof (FTP));
  225. X  
  226. X  if ((host=FtpGetHost(hostname))==NULL)
  227. X    return EXIT((*con),QUIT);
  228. X  if ((service=(struct servent *) getservbyname("ftp","tcp"))==0)
  229. X    return EXIT((*con),QUIT);
  230. X  
  231. X  unit.sin_family = host -> h_addrtype;
  232. X  
  233. X  bcopy(host-> h_addr_list[0],(char *)&unit.sin_addr,host->h_length);
  234. X  if ( ( sock = socket ( unit.sin_family , SOCK_STREAM , 0)) < 0)
  235. X    return EXIT((*con),QUIT);
  236. X
  237. X  unit.sin_port = service -> s_port;
  238. X
  239. X  while ( connect ( sock , &unit , sizeof unit ) < 0 )
  240. X    {
  241. X      host -> h_addr_list ++;
  242. X      if (host -> h_addr_list[0]==NULL) {
  243. X    close(sock);
  244. X    return EXIT((*con),QUIT);
  245. X      }
  246. X      bcopy(host -> h_addr_list[0],(char *)&unit,host->h_length);
  247. X      close(sock);
  248. X      if ( ( sock = socket ( unit.sin_family , SOCK_STREAM , 0)) < 0)
  249. X    {
  250. X      close(sock);
  251. X      return EXIT((*con),QUIT);
  252. X    }
  253. X    }
  254. X  
  255. X  (*con) -> sock = sock;
  256. X  (*con) -> mode = 'A';
  257. X  (*con) -> data = 0;
  258. X  (*con) -> func = NULL;
  259. X  (*con) -> debug = NULL;
  260. X
  261. X  if (ftplib_debug) FtpDebug(*con);
  262. X
  263. X  if ( (x=FtpGetMessage(*con,S1)) == QUIT )
  264. X    return EXIT((*con),QUIT);
  265. X  if ( ! FtpGood(x,120,220,EOF))
  266. X    {
  267. X      close(sock);
  268. X      return EXIT((*con),-x);
  269. X    }
  270. X  return EXIT((*con),x);
  271. X}
  272. X
  273. X
  274. X
  275. END_OF_FILE
  276.   if test 1841 -ne `wc -c <'libftp/FtpConnect.c'`; then
  277.     echo shar: \"'libftp/FtpConnect.c'\" unpacked with wrong size!
  278.   fi
  279.   # end of 'libftp/FtpConnect.c'
  280. fi
  281. if test -f 'libftp/FtpDebug.c' -a "${1}" != "-c" ; then 
  282.   echo shar: Will not clobber existing file \"'libftp/FtpDebug.c'\"
  283. else
  284.   echo shar: Extracting \"'libftp/FtpDebug.c'\" \(1065 characters\)
  285.   sed "s/^X//" >'libftp/FtpDebug.c' <<'END_OF_FILE'
  286. X/*
  287. X              Library for ftpd clients.(libftp)
  288. X            Copyright by Oleg Orel
  289. X             All rights reserved.
  290. X            
  291. XThis  library is desined  for  free,  non-commercial  software  creation. 
  292. XIt is changeable and can be improved. The author would greatly appreciate 
  293. Xany  advises, new  components  and  patches  of  the  existing  programs.
  294. XCommercial  usage is  also  possible  with  participation of it's author.
  295. X
  296. X
  297. X
  298. X*/
  299. X
  300. X#include "FtpLibrary.h"
  301. X
  302. Xint ftplib_debug=FTP_nodebug;
  303. X
  304. X#define __EXIT if (ftplib_debug!=FTP_noexit) exit(-1)
  305. X
  306. Xvoid FtpDebug(FTP *ftp)
  307. X{
  308. X  STATUS FtpDebugDebug(),
  309. X         FtpDebugError(),
  310. X         FtpDebugIO();
  311. X
  312. X  FtpSetDebugHandler(ftp,FtpDebugDebug);
  313. X  FtpSetErrorHandler(ftp,FtpDebugError);
  314. X  FtpSetIOHandler(ftp,FtpDebugIO);
  315. X}
  316. X
  317. XSTATUS FtpDebugDebug(FTP *ftp,int n, char * Message)
  318. X{
  319. X  fprintf(stderr,"DEBUG:: %s\n",Message);
  320. X  return 1;
  321. X}
  322. X
  323. XSTATUS FtpDebugError(FTP *ftp,int n, char * Message)
  324. X{
  325. X  fprintf(stderr,"Abort:: %s\n",Message);
  326. X  __EXIT;
  327. X}
  328. X
  329. XSTATUS FtpDebugIO(FTP *ftp,int n, char * Message)
  330. X{
  331. X  fprintf(stderr,"IO");
  332. X  perror("");
  333. X  __EXIT;
  334. X}
  335. X
  336. X
  337. X
  338. END_OF_FILE
  339.   if test 1065 -ne `wc -c <'libftp/FtpDebug.c'`; then
  340.     echo shar: \"'libftp/FtpDebug.c'\" unpacked with wrong size!
  341.   fi
  342.   # end of 'libftp/FtpDebug.c'
  343. fi
  344. if test -f 'libftp/FtpFopen.c' -a "${1}" != "-c" ; then 
  345.   echo shar: Will not clobber existing file \"'libftp/FtpFopen.c'\"
  346. else
  347.   echo shar: Extracting \"'libftp/FtpFopen.c'\" \(749 characters\)
  348.   sed "s/^X//" >'libftp/FtpFopen.c' <<'END_OF_FILE'
  349. X/*
  350. X              Library for ftpd clients.(libftp)
  351. X            Copyright by Oleg Orel
  352. X             All rights reserved.
  353. X            
  354. XThis  library is desined  for  free,  non-commercial  software  creation. 
  355. XIt is changeable and can be improved. The author would greatly appreciate 
  356. Xany  advises, new  components  and  patches  of  the  existing  programs.
  357. XCommercial  usage is  also  possible  with  participation of it's author.
  358. X
  359. X
  360. X
  361. X*/
  362. X
  363. X#include <FtpLibrary.h>
  364. X
  365. X
  366. XFILE *Ftpfopen(char *filename,char *mode)
  367. X{
  368. X  
  369. X
  370. X  if (strcmp(filename,"*STDIN*")==0)
  371. X    return fdopen(stdin->_file,mode);
  372. X  
  373. X  if (strcmp(filename,"*STDOUT*")==0)
  374. X    return fdopen(stdout->_file,mode);
  375. X  
  376. X  if (strcmp(filename,"*STDERR*")==0)
  377. X    return fdopen(stderr->_file,mode);
  378. X
  379. X  return fopen(filename,mode);
  380. X}
  381. X
  382. END_OF_FILE
  383.   if test 749 -ne `wc -c <'libftp/FtpFopen.c'`; then
  384.     echo shar: \"'libftp/FtpFopen.c'\" unpacked with wrong size!
  385.   fi
  386.   # end of 'libftp/FtpFopen.c'
  387. fi
  388. if test -f 'libftp/FtpGetMessage.c' -a "${1}" != "-c" ; then 
  389.   echo shar: Will not clobber existing file \"'libftp/FtpGetMessage.c'\"
  390. else
  391.   echo shar: Extracting \"'libftp/FtpGetMessage.c'\" \(1037 characters\)
  392.   sed "s/^X//" >'libftp/FtpGetMessage.c' <<'END_OF_FILE'
  393. X/*
  394. X              Library for ftpd clients.(libftp)
  395. X            Copyright by Oleg Orel
  396. X             All rights reserved.
  397. X            
  398. XThis  library is desined  for  free,  non-commercial  software  creation. 
  399. XIt is changeable and can be improved. The author would greatly appreciate 
  400. Xany  advises, new  components  and  patches  of  the  existing  programs.
  401. XCommercial  usage is  also  possible  with  participation of it's author.
  402. X
  403. X
  404. X
  405. X*/
  406. X
  407. X#include "FtpLibrary.h"
  408. X
  409. Xextern char * FtpMessageList[];
  410. X
  411. Xint FtpGetMessage(FTP *con , char * Message )
  412. X{
  413. X  int i=0,n;
  414. X  FILE *in=fdopen(con->sock,"r");
  415. X  String tmp;
  416. X  
  417. X  while(1)
  418. X    {
  419. X      if (fgets(tmp,sizeof tmp,in)==NULL) return QUIT;
  420. X      tmp[strlen(tmp)-1]='\0';
  421. X      if (tmp[3]!='-') break;
  422. X      if ( con -> debug != NULL )
  423. X    (*con->debug)(con,n,tmp);
  424. X    }
  425. X
  426. X  strcpy(Message,tmp); 
  427. X  FtpInitMessageList();
  428. X  FtpMessageList[n=FtpNumber(Message)] =
  429. X    ( char * ) malloc ( strlen(Message) + 1);
  430. X  strcpy(FtpMessageList[n] , Message );
  431. X  if ( con -> debug != NULL )
  432. X    (*con->debug)(con,n,Message);
  433. X
  434. X  return n;
  435. X}
  436. X      
  437. END_OF_FILE
  438.   if test 1037 -ne `wc -c <'libftp/FtpGetMessage.c'`; then
  439.     echo shar: \"'libftp/FtpGetMessage.c'\" unpacked with wrong size!
  440.   fi
  441.   # end of 'libftp/FtpGetMessage.c'
  442. fi
  443. if test -f 'libftp/FtpGetString.c' -a "${1}" != "-c" ; then 
  444.   echo shar: Will not clobber existing file \"'libftp/FtpGetString.c'\"
  445. else
  446.   echo shar: Extracting \"'libftp/FtpGetString.c'\" \(659 characters\)
  447.   sed "s/^X//" >'libftp/FtpGetString.c' <<'END_OF_FILE'
  448. X/*
  449. X              Library for ftpd clients.(libftp)
  450. X            Copyright by Oleg Orel
  451. X             All rights reserved.
  452. X            
  453. XThis  library is desined  for  free,  non-commercial  software  creation. 
  454. XIt is changeable and can be improved. The author would greatly appreciate 
  455. Xany  advises, new  components  and  patches  of  the  existing  programs.
  456. XCommercial  usage is  also  possible  with  participation of it's author.
  457. X
  458. X
  459. X
  460. X*/
  461. X
  462. X#include "FtpLibrary.h"
  463. X
  464. XSTATUS FtpGetString(FTP *con ,char * str )
  465. X{
  466. X  int i=0;
  467. X  while ( (str[i]=FtpRead(con)) != '\n' && str[i] != EOF ) i++;
  468. X  if ( str[i] != EOF )
  469. X    { 
  470. X      str[i] = '\0';
  471. X      return i;
  472. X    }
  473. X  str[i] = '\0';
  474. X  return EOF;
  475. X}
  476. X  
  477. END_OF_FILE
  478.   if test 659 -ne `wc -c <'libftp/FtpGetString.c'`; then
  479.     echo shar: \"'libftp/FtpGetString.c'\" unpacked with wrong size!
  480.   fi
  481.   # end of 'libftp/FtpGetString.c'
  482. fi
  483. if test -f 'libftp/FtpGood.c' -a "${1}" != "-c" ; then 
  484.   echo shar: Will not clobber existing file \"'libftp/FtpGood.c'\"
  485. else
  486.   echo shar: Extracting \"'libftp/FtpGood.c'\" \(1014 characters\)
  487.   sed "s/^X//" >'libftp/FtpGood.c' <<'END_OF_FILE'
  488. X/*
  489. X              Library for ftpd clients.(libftp)
  490. X            Copyright by Oleg Orel
  491. X             All rights reserved.
  492. X            
  493. XThis  library is desined  for  free,  non-commercial  software  creation. 
  494. XIt is changeable and can be improved. The author would greatly appreciate 
  495. Xany  advises, new  components  and  patches  of  the  existing  programs.
  496. XCommercial  usage is  also  possible  with  participation of it's author.
  497. X
  498. X
  499. X
  500. X*/
  501. X
  502. X#include "FtpLibrary.h"
  503. X
  504. X#include <varargs.h>
  505. X
  506. XSTATUS FtpGood(va_alist)
  507. X     va_dcl
  508. X{
  509. X  va_list args;
  510. X  int Number;
  511. X  int Answer[MAX_ANSWERS];
  512. X  int counter=0;
  513. X  
  514. X  va_start(args);
  515. X
  516. X  Number = va_arg(args,int);
  517. X  
  518. X  while ( 1 )
  519. X    {
  520. X      if (counter == MAX_ANSWERS)
  521. X    return 0;
  522. X      Answer[counter] = va_arg(args,int);
  523. X      if (Answer[counter] == EOF ) break;
  524. X      counter++;
  525. X    }
  526. X
  527. X  va_end(args);
  528. X  
  529. X  return FtpGood1(Number,Answer);
  530. X}
  531. X
  532. X
  533. XSTATUS FtpGood1(int Number , int *Answer)
  534. X{
  535. X  while (1)
  536. X    {
  537. X      if ( *Answer == Number) return 1;
  538. X      if ( *Answer == EOF ) return 0;
  539. X      Answer++;
  540. X    }
  541. X}
  542. X
  543. END_OF_FILE
  544.   if test 1014 -ne `wc -c <'libftp/FtpGood.c'`; then
  545.     echo shar: \"'libftp/FtpGood.c'\" unpacked with wrong size!
  546.   fi
  547.   # end of 'libftp/FtpGood.c'
  548. fi
  549. if test -f 'libftp/FtpInitMessage.c' -a "${1}" != "-c" ; then 
  550.   echo shar: Will not clobber existing file \"'libftp/FtpInitMessage.c'\"
  551. else
  552.   echo shar: Extracting \"'libftp/FtpInitMessage.c'\" \(620 characters\)
  553.   sed "s/^X//" >'libftp/FtpInitMessage.c' <<'END_OF_FILE'
  554. X/*
  555. X              Library for ftpd clients.(libftp)
  556. X            Copyright by Oleg Orel
  557. X             All rights reserved.
  558. X            
  559. XThis  library is desined  for  free,  non-commercial  software  creation. 
  560. XIt is changeable and can be improved. The author would greatly appreciate 
  561. Xany  advises, new  components  and  patches  of  the  existing  programs.
  562. XCommercial  usage is  also  possible  with  participation of it's author.
  563. X
  564. X
  565. X
  566. X*/
  567. X
  568. X#include "FtpLibrary.h"
  569. X
  570. Xchar * FtpMessageList[1000];
  571. X
  572. XSTATUS FtpInitMessageList()
  573. X{
  574. X  int i;
  575. X  static u = 0;
  576. X  
  577. X  if ( u )
  578. X    return 1;
  579. X
  580. X  u = 1;
  581. X
  582. X  for (i=0;i<1000;i++)
  583. X    FtpMessageList[i]=NULL;
  584. X
  585. X  return 1;
  586. X}
  587. END_OF_FILE
  588.   if test 620 -ne `wc -c <'libftp/FtpInitMessage.c'`; then
  589.     echo shar: \"'libftp/FtpInitMessage.c'\" unpacked with wrong size!
  590.   fi
  591.   # end of 'libftp/FtpInitMessage.c'
  592. fi
  593. if test -f 'libftp/FtpLibrary.h' -a "${1}" != "-c" ; then 
  594.   echo shar: Will not clobber existing file \"'libftp/FtpLibrary.h'\"
  595. else
  596.   echo shar: Extracting \"'libftp/FtpLibrary.h'\" \(5437 characters\)
  597.   sed "s/^X//" >'libftp/FtpLibrary.h' <<'END_OF_FILE'
  598. X/*
  599. X              Library for ftpd clients.(libftp)
  600. X            Copyright by Oleg Orel
  601. X             All rights reserved.
  602. X            
  603. XThis  library is desined  for  free,  non-commercial  software  creation. 
  604. XIt is changeable and can be improved. The author would greatly appreciate 
  605. Xany  advises, new  components  and  patches  of  the  existing  programs.
  606. XCommercial  usage is  also  possible  with  participation of it's author.
  607. X
  608. X
  609. X
  610. X*/
  611. X  
  612. X#ifndef __FTPLIBRARY_H
  613. X#define __FTPLIBRARY_H
  614. X
  615. X
  616. X#ifdef __cplusplus
  617. X    extern "C" {
  618. X#endif
  619. X#include <stdio.h>
  620. X#include <sys/types.h>
  621. X#include <sys/socket.h>
  622. X#include <arpa/ftp.h>
  623. X#include <netinet/in.h>
  624. X#include <netdb.h>
  625. X
  626. X#ifdef _AIX
  627. Xint accept (int, struct sockaddr_in*, int*);
  628. Xchar *bcopy (char*, char*, size_t);
  629. Xint bind (int, const void*, int);
  630. Xint connect (int, struct sockaddr_in*, int);
  631. Xint gethostname (char*, size_t);
  632. Xint getsockname (int, struct sockaddr_in*, int*);
  633. Xint getpeername (int, struct sockaddr_in*, int*);
  634. Xint getsockopt (int, int, int, void*, int*);
  635. Xint listen(int, int);
  636. Xint setsockopt (int, int, int, (size_t);
  637. Xint socket (int, int, int);
  638. Xvoid free (void*);
  639. Xvoid *malloc (size_t);
  640. X#endif
  641. X
  642. Xextern int errno;
  643. X        
  644. X
  645. X        /* Standard Macros & Definitions */
  646. X
  647. X        
  648. X      
  649. X#define EXIT(con,e) \
  650. X  ( con -> errno = e,  \
  651. X    ((con->func != NULL) && (e < 0) )?(*(con->func))(con,e,FtpMessage(e)) : 0,\
  652. X    ((e==QUIT)&&(con->IO != NULL))?(*(con->IO))(con,errno,strerror(errno)):0,\
  653. X     e\
  654. X  )
  655. X   
  656. X#define MAX_ANSWERS 10 /* Number of known goodest answers for reqest */
  657. X#define QUIT 0
  658. X#define Ctrl(x) ((x) - '@')
  659. X#define FREE(x) memset ( &x , '\0' , sizeof x )
  660. X#define CUT(x) ((x)&0xff)
  661. X
  662. Xtypedef int STATUS;
  663. Xtypedef char String[256];
  664. X
  665. X
  666. X        /* Common Information Structure */
  667. X
  668. Xtypedef struct
  669. X{
  670. X  int sock;
  671. X  FILE *data;
  672. X  char mode;
  673. X  int errno;
  674. X  int ch;
  675. X  STATUS (*func)();
  676. X  STATUS (*debug)();
  677. X  STATUS (*IO)();
  678. X} FTP;
  679. X
  680. Xenum {FTP_nodebug,FTP_debug,FTP_noexit};
  681. X
  682. Xextern int ftplib_debug;
  683. X
  684. X/* Connect & disconnect */ 
  685. X
  686. XSTATUS  FtpConnect(FTP **con,char *hostname);
  687. X#define FtpUser(ftp,user)           FtpCommand(ftp,"USER %s",user,230,331,332,EOF)
  688. X#define FtpPassword(ftp,pas)        FtpCommand(ftp,"PASS %s",pas,230,332,EOF)
  689. X#define FtpAccount(ftp,acc)         FtpCommand(ftp,"ACCT %s",acc,230,EOF)
  690. XSTATUS  FtpLogin(FTP **con,char *host ,char *user,char *pass,char *acct);
  691. XSTATUS  FtpBye (FTP * con);
  692. X
  693. X/* Set type of transfer */
  694. X
  695. X#define FtpAscii(ftp)               FtpType(ftp,"A")
  696. X#define FtpBinary(ftp)              FtpType(ftp,"I")
  697. X
  698. X
  699. X/* Receive Procedures */
  700. X
  701. XSTATUS  FtpRetrTimeout(FTP *con, char *command,char *inp,char *out,long time);
  702. X#define FtpRetr(ftp,com,inp,out)    FtpRetrTimeout(ftp,com,inp,out,0)
  703. X#define FtpGet(ftp,in,out)          FtpRetr(ftp,"RETR %s",in,out)
  704. X#define FtpGetTimeout(ftp,in,out,t) FtpRetrTimeout(ftp,"RETR %s",in,out,t)
  705. X#define FtpDirectory(ftp,pat,out)   FtpRetr(ftp,"LIST %s",pat,out)
  706. X#define FtpDir(ftp,out)             FtpRetr(ftp,"LIST","",out)
  707. X
  708. X/* Send Procedures */
  709. X
  710. XSTATUS  FtpStorTimeout(FTP *con ,char*command ,char *inp,char *out,long time);
  711. X#define FtpStor(ftp,com,inp,out)    FtpStorTimeout(ftp,com,imp,out,0)
  712. X#define FtpPut(ftp,in,out)          FtpStor(ftp,"STOR %s",in,out)
  713. X#define FtpPutTimeout(ftp,in,out,t) FtpStorTimeout(ftp,"STOR %s",in,out,t)
  714. X
  715. X/* Command for remote server for startup transfer */
  716. X
  717. X#define FtpGetFile(ftp,file)        FtpCommand(ftp,"RETR %s",file,\
  718. X                         200,125,150,250,EOF)
  719. X#define FtpPutFile(ftp,file)        FtpCommand(ftp,"STOR %s",file,\
  720. X                        200,125,150,250,EOF)
  721. X
  722. X/* Command for remote server for startup transfer and make data connection */
  723. X
  724. XSTATUS  FtpData( FTP * con , char * command , char * param , char *mode);
  725. XSTATUS  FtpPort ( FTP *con ,int ,int ,int ,int ,int ,int );
  726. X#define FtpOpenRead(ftp,file)       FtpData(ftp,"RETR %s",file,"r")
  727. X#define FtpOpenWrite(ftp,file)      FtpData(ftp,"STOR %s",file,"w")
  728. X#define FtpOpenAppend(ftp,file)     FtpData(ftp,"APPE %s",file,"r")
  729. XSTATUS  FtpOpenDir( FTP * con , char * files );
  730. XSTATUS  FtpClose ( FTP *);
  731. X
  732. X/* Command for handing transfer */
  733. X
  734. XSTATUS  FtpGetString ( FTP * con , char * str );
  735. XSTATUS  FtpRead ( FTP * con);
  736. XSTATUS  FtpWrite ( FTP * con , char c);
  737. X
  738. X
  739. X/* Manipulation commands for remote server */
  740. X
  741. XSTATUS  FtpCommand ();
  742. X#define FtpChdir(ftp,dir)           FtpCommand(ftp,"CWD %s",dir,200,250,EOF)
  743. X#define FtpMkdir(ftp,dir)           FtpCommand(ftp,"MKD %s",dir,200,257,EOF)
  744. X#define FtpRm(ftp,dir)              FtpCommand(ftp,"DELE %s",dir,200,250,EOF)
  745. Xchar   *FtpPwd(FTP *con);
  746. XSTATUS  FtpMove ( FTP *con,char * old,char *new);
  747. X
  748. X/* Procedures for dialog with remote server */
  749. X
  750. XSTATUS  FtpInitMessageList();
  751. XSTATUS  FtpSendMessage( FTP * con , char * Message );
  752. Xint     FtpGetMessage( FTP * con , char * Message);
  753. Xchar   *FtpMessage(int Number);
  754. Xint     FtpNumber ( char * Message );
  755. X
  756. X
  757. X/* Debug */
  758. X
  759. X#define FtpSetErrorHandler(con,f) con->func = f
  760. X#define FtpSetDebugHandler(con,f) con->debug = f 
  761. X#define FtpSetIOHandler(con,f) con->IO =f
  762. X#define FtplibDebug(t) ftplib_debug=t
  763. XSTATUS  FtpDebugDebug ( FTP *con, int errno, char * Message);
  764. XSTATUS  FtpDebugError ( FTP *con, int errno, char * Message);
  765. XSTATUS  FtpDebugIO    ( FTP *con, int errno, char * Message);
  766. Xvoid    FtpDebug ( FTP * con );
  767. X
  768. X
  769. X/* Other Procedures */
  770. X
  771. XFILE   *FtpFullOpen(char * file,char * mode );
  772. XFILE   *Ftpfopen(char *filename,char *mode);
  773. XSTATUS  FtpFullClose(FILE *);
  774. XSTATUS  FtpGood ();
  775. Xstruct  hostent *FtpGetHost(char *host);
  776. X
  777. X#ifdef __cplusplus
  778. X}
  779. X#endif
  780. X      
  781. X
  782. X#endif /* __FTPLIBRARYH_ */
  783. X
  784. X
  785. X
  786. END_OF_FILE
  787.   if test 5437 -ne `wc -c <'libftp/FtpLibrary.h'`; then
  788.     echo shar: \"'libftp/FtpLibrary.h'\" unpacked with wrong size!
  789.   fi
  790.   # end of 'libftp/FtpLibrary.h'
  791. fi
  792. if test -f 'libftp/FtpLogin.c' -a "${1}" != "-c" ; then 
  793.   echo shar: Will not clobber existing file \"'libftp/FtpLogin.c'\"
  794. else
  795.   echo shar: Extracting \"'libftp/FtpLogin.c'\" \(885 characters\)
  796.   sed "s/^X//" >'libftp/FtpLogin.c' <<'END_OF_FILE'
  797. X/*
  798. X              Library for ftpd clients.(libftp)
  799. X            Copyright by Oleg Orel
  800. X             All rights reserved.
  801. X            
  802. XThis  library is desined  for  free,  non-commercial  software  creation. 
  803. XIt is changeable and can be improved. The author would greatly appreciate 
  804. Xany  advises, new  components  and  patches  of  the  existing  programs.
  805. XCommercial  usage is  also  possible  with  participation of it's author.
  806. X
  807. X
  808. X
  809. X*/
  810. X
  811. X#include "FtpLibrary.h"
  812. X
  813. XSTATUS FtpLogin ( FTP ** con, char * host , char * user , 
  814. X          char * password , char * account)
  815. X{
  816. X  STATUS x;
  817. X  
  818. X  if ( (x=FtpConnect(con,host)) < 1)
  819. X    return x;
  820. X  if ( (x=FtpUser(*con,user)) < 1)
  821. X    return x;
  822. X  if ( x==230 )
  823. X    return x;
  824. X  if ( x==332)
  825. X    {
  826. X      if ( account == NULL )
  827. X    return EXIT((*con),x);
  828. X      if ( (x=FtpAccount( *con , account )) < 1 )
  829. X    return x;
  830. X      if ( x==230 )
  831. X    return x;
  832. X    }
  833. X  return FtpPassword(*con,password);
  834. X}
  835. END_OF_FILE
  836.   if test 885 -ne `wc -c <'libftp/FtpLogin.c'`; then
  837.     echo shar: \"'libftp/FtpLogin.c'\" unpacked with wrong size!
  838.   fi
  839.   # end of 'libftp/FtpLogin.c'
  840. fi
  841. if test -f 'libftp/FtpMessage.c' -a "${1}" != "-c" ; then 
  842.   echo shar: Will not clobber existing file \"'libftp/FtpMessage.c'\"
  843. else
  844.   echo shar: Extracting \"'libftp/FtpMessage.c'\" \(660 characters\)
  845.   sed "s/^X//" >'libftp/FtpMessage.c' <<'END_OF_FILE'
  846. X/*
  847. X              Library for ftpd clients.(libftp)
  848. X            Copyright by Oleg Orel
  849. X             All rights reserved.
  850. X            
  851. XThis  library is desined  for  free,  non-commercial  software  creation. 
  852. XIt is changeable and can be improved. The author would greatly appreciate 
  853. Xany  advises, new  components  and  patches  of  the  existing  programs.
  854. XCommercial  usage is  also  possible  with  participation of it's author.
  855. X
  856. X
  857. X
  858. X*/
  859. X
  860. X#include "FtpLibrary.h"
  861. X
  862. Xextern char * FtpMessageList[];
  863. X
  864. Xchar *FtpMessage(int number)
  865. X{
  866. X  FtpInitMessageList();
  867. X  if ( number == 0 )
  868. X    return "I/O Error , use perror";
  869. X  return (FtpMessageList[abs(number)]==NULL)?
  870. X    "":FtpMessageList[abs(number)];
  871. X}
  872. END_OF_FILE
  873.   if test 660 -ne `wc -c <'libftp/FtpMessage.c'`; then
  874.     echo shar: \"'libftp/FtpMessage.c'\" unpacked with wrong size!
  875.   fi
  876.   # end of 'libftp/FtpMessage.c'
  877. fi
  878. if test -f 'libftp/FtpMove.c' -a "${1}" != "-c" ; then 
  879.   echo shar: Will not clobber existing file \"'libftp/FtpMove.c'\"
  880. else
  881.   echo shar: Extracting \"'libftp/FtpMove.c'\" \(646 characters\)
  882.   sed "s/^X//" >'libftp/FtpMove.c' <<'END_OF_FILE'
  883. X/*
  884. X              Library for ftpd clients.(libftp)
  885. X            Copyright by Oleg Orel
  886. X             All rights reserved.
  887. X            
  888. XThis  library is desined  for  free,  non-commercial  software  creation. 
  889. XIt is changeable and can be improved. The author would greatly appreciate 
  890. Xany  advises, new  components  and  patches  of  the  existing  programs.
  891. XCommercial  usage is  also  possible  with  participation of it's author.
  892. X
  893. X
  894. X
  895. X*/
  896. X
  897. X#include "FtpLibrary.h"
  898. X
  899. XSTATUS FtpMove(FTP *con,char * oldname , char * newname )
  900. X{
  901. X  STATUS i;
  902. X
  903. X  if ((i=FtpCommand(con,"RNFR %s",oldname,200,350,EOF)) > 1 )
  904. X    return FtpCommand(con,"RNTO %s",newname,200,250,EOF);
  905. X  else
  906. X    return i;
  907. X}
  908. END_OF_FILE
  909.   if test 646 -ne `wc -c <'libftp/FtpMove.c'`; then
  910.     echo shar: \"'libftp/FtpMove.c'\" unpacked with wrong size!
  911.   fi
  912.   # end of 'libftp/FtpMove.c'
  913. fi
  914. if test -f 'libftp/FtpNumber.c' -a "${1}" != "-c" ; then 
  915.   echo shar: Will not clobber existing file \"'libftp/FtpNumber.c'\"
  916. else
  917.   echo shar: Extracting \"'libftp/FtpNumber.c'\" \(558 characters\)
  918.   sed "s/^X//" >'libftp/FtpNumber.c' <<'END_OF_FILE'
  919. X/*
  920. X              Library for ftpd clients.(libftp)
  921. X            Copyright by Oleg Orel
  922. X             All rights reserved.
  923. X            
  924. XThis  library is desined  for  free,  non-commercial  software  creation. 
  925. XIt is changeable and can be improved. The author would greatly appreciate 
  926. Xany  advises, new  components  and  patches  of  the  existing  programs.
  927. XCommercial  usage is  also  possible  with  participation of it's author.
  928. X
  929. X
  930. X
  931. X*/
  932. X
  933. X#include "FtpLibrary.h"
  934. X
  935. Xint FtpNumber(char *Message)
  936. X{
  937. X  return (Message[0] - '0') * 100 +
  938. X         (Message[1] - '0') * 10  +
  939. X     (Message[2] - '0') ;
  940. X}
  941. END_OF_FILE
  942.   if test 558 -ne `wc -c <'libftp/FtpNumber.c'`; then
  943.     echo shar: \"'libftp/FtpNumber.c'\" unpacked with wrong size!
  944.   fi
  945.   # end of 'libftp/FtpNumber.c'
  946. fi
  947. if test -f 'libftp/FtpOpenDir.c' -a "${1}" != "-c" ; then 
  948.   echo shar: Will not clobber existing file \"'libftp/FtpOpenDir.c'\"
  949. else
  950.   echo shar: Extracting \"'libftp/FtpOpenDir.c'\" \(659 characters\)
  951.   sed "s/^X//" >'libftp/FtpOpenDir.c' <<'END_OF_FILE'
  952. X/*
  953. X              Library for ftpd clients.(libftp)
  954. X            Copyright by Oleg Orel
  955. X             All rights reserved.
  956. X            
  957. XThis  library is desined  for  free,  non-commercial  software  creation. 
  958. XIt is changeable and can be improved. The author would greatly appreciate 
  959. Xany  advises, new  components  and  patches  of  the  existing  programs.
  960. XCommercial  usage is  also  possible  with  participation of it's author.
  961. X
  962. X
  963. X
  964. X*/
  965. X
  966. X#include "FtpLibrary.h"
  967. X
  968. XSTATUS FtpOpenDir(FTP * con,char * file)
  969. X{
  970. X  String command;
  971. X
  972. X  if ( file == NULL || *file == '\0' )
  973. X    strcpy(command,"NLST");
  974. X  else
  975. X    sprintf(command,"NLST %s",file);
  976. X
  977. X  return FtpCommand(con,command,"",120,150,200,EOF);
  978. X}
  979. END_OF_FILE
  980.   if test 659 -ne `wc -c <'libftp/FtpOpenDir.c'`; then
  981.     echo shar: \"'libftp/FtpOpenDir.c'\" unpacked with wrong size!
  982.   fi
  983.   # end of 'libftp/FtpOpenDir.c'
  984. fi
  985. if test -f 'libftp/FtpPort.c' -a "${1}" != "-c" ; then 
  986.   echo shar: Will not clobber existing file \"'libftp/FtpPort.c'\"
  987. else
  988.   echo shar: Extracting \"'libftp/FtpPort.c'\" \(776 characters\)
  989.   sed "s/^X//" >'libftp/FtpPort.c' <<'END_OF_FILE'
  990. X/*
  991. X              Library for ftpd clients.(libftp)
  992. X            Copyright by Oleg Orel
  993. X             All rights reserved.
  994. X            
  995. XThis  library is desined  for  free,  non-commercial  software  creation. 
  996. XIt is changeable and can be improved. The author would greatly appreciate 
  997. Xany  advises, new  components  and  patches  of  the  existing  programs.
  998. XCommercial  usage is  also  possible  with  participation of it's author.
  999. X
  1000. X
  1001. X
  1002. X*/
  1003. X
  1004. X#include "FtpLibrary.h"
  1005. X
  1006. XSTATUS FtpPort(FTP *con,int a,int b,int c,int d,int e,int f)
  1007. X{
  1008. X  String cmd;
  1009. X  int i;
  1010. X
  1011. X  sprintf(cmd,"PORT %d,%d,%d,%d,%d,%d",a,b,c,d,e,f);
  1012. X  if ( FtpSendMessage(con,cmd) == QUIT)
  1013. X    return QUIT;
  1014. X  if ( (i=FtpGetMessage(con,cmd)) == QUIT)
  1015. X    return QUIT;
  1016. X  
  1017. X  if ( ! FtpGood ( i , 200 , EOF ))
  1018. X    return EXIT(con,-i);
  1019. X
  1020. X  return EXIT(con,i);
  1021. X}
  1022. END_OF_FILE
  1023.   if test 776 -ne `wc -c <'libftp/FtpPort.c'`; then
  1024.     echo shar: \"'libftp/FtpPort.c'\" unpacked with wrong size!
  1025.   fi
  1026.   # end of 'libftp/FtpPort.c'
  1027. fi
  1028. if test -f 'libftp/FtpPwd.c' -a "${1}" != "-c" ; then 
  1029.   echo shar: Will not clobber existing file \"'libftp/FtpPwd.c'\"
  1030. else
  1031.   echo shar: Extracting \"'libftp/FtpPwd.c'\" \(782 characters\)
  1032.   sed "s/^X//" >'libftp/FtpPwd.c' <<'END_OF_FILE'
  1033. X/*
  1034. X              Library for ftpd clients.(libftp)
  1035. X            Copyright by Oleg Orel
  1036. X             All rights reserved.
  1037. X            
  1038. XThis  library is desined  for  free,  non-commercial  software  creation. 
  1039. XIt is changeable and can be improved. The author would greatly appreciate 
  1040. Xany  advises, new  components  and  patches  of  the  existing  programs.
  1041. XCommercial  usage is  also  possible  with  participation of it's author.
  1042. X
  1043. X
  1044. X
  1045. X*/
  1046. X
  1047. X#include "FtpLibrary.h"
  1048. X
  1049. Xchar * FtpPwd(FTP * con)
  1050. X{
  1051. X  String tmp,tmp1;
  1052. X  int i;
  1053. X  
  1054. X  if ( FtpSendMessage(con,"PWD") == QUIT )
  1055. X    return (char *) EXIT(con,QUIT);
  1056. X  if ( (i=FtpGetMessage(con,tmp)) == QUIT )
  1057. X    return (char *) EXIT(con,QUIT);
  1058. X  
  1059. X  if ( i != 257 )
  1060. X    return (char *) EXIT(con,-i);
  1061. X
  1062. X  sscanf(tmp,"%*[^\"]%*c%[^\"]%*s",tmp1);
  1063. X  con -> errno = i;
  1064. X  return tmp1;
  1065. X}
  1066. END_OF_FILE
  1067.   if test 782 -ne `wc -c <'libftp/FtpPwd.c'`; then
  1068.     echo shar: \"'libftp/FtpPwd.c'\" unpacked with wrong size!
  1069.   fi
  1070.   # end of 'libftp/FtpPwd.c'
  1071. fi
  1072. if test -f 'libftp/FtpRead.c' -a "${1}" != "-c" ; then 
  1073.   echo shar: Will not clobber existing file \"'libftp/FtpRead.c'\"
  1074. else
  1075.   echo shar: Extracting \"'libftp/FtpRead.c'\" \(819 characters\)
  1076.   sed "s/^X//" >'libftp/FtpRead.c' <<'END_OF_FILE'
  1077. X/*
  1078. X              Library for ftpd clients.(libftp)
  1079. X            Copyright by Oleg Orel
  1080. X             All rights reserved.
  1081. X            
  1082. XThis  library is desined  for  free,  non-commercial  software  creation. 
  1083. XIt is changeable and can be improved. The author would greatly appreciate 
  1084. Xany  advises, new  components  and  patches  of  the  existing  programs.
  1085. XCommercial  usage is  also  possible  with  participation of it's author.
  1086. X
  1087. X
  1088. X
  1089. X*/
  1090. X
  1091. X#include "FtpLibrary.h"
  1092. X
  1093. Xint FtpRead(FTP *con)
  1094. X{
  1095. X  int c;
  1096. X  
  1097. X  if ( con -> mode == 'I' )
  1098. X    return getc(con->data);
  1099. X  
  1100. X  if ( con->ch != EOF )
  1101. X    {
  1102. X      c=con->ch;
  1103. X      con->ch=EOF;
  1104. X      return c;
  1105. X    }
  1106. X  
  1107. X  c=getc(con->data);
  1108. X  
  1109. X  if ( c == Ctrl('M') )
  1110. X    {
  1111. X      c = getc ( con->data);
  1112. X      
  1113. X      if ( c == Ctrl('J') )
  1114. X        return '\n';
  1115. X      con->ch = c;
  1116. X      return Ctrl('M');
  1117. X    }
  1118. X  return c;
  1119. X}
  1120. X      
  1121. END_OF_FILE
  1122.   if test 819 -ne `wc -c <'libftp/FtpRead.c'`; then
  1123.     echo shar: \"'libftp/FtpRead.c'\" unpacked with wrong size!
  1124.   fi
  1125.   # end of 'libftp/FtpRead.c'
  1126. fi
  1127. if test -f 'libftp/FtpRetrTimeout.c' -a "${1}" != "-c" ; then 
  1128.   echo shar: Will not clobber existing file \"'libftp/FtpRetrTimeout.c'\"
  1129. else
  1130.   echo shar: Extracting \"'libftp/FtpRetrTimeout.c'\" \(1070 characters\)
  1131.   sed "s/^X//" >'libftp/FtpRetrTimeout.c' <<'END_OF_FILE'
  1132. X/*
  1133. X              Library for ftpd clients.(libftp)
  1134. X            Copyright by Oleg Orel
  1135. X             All rights reserved.
  1136. X            
  1137. XThis  library is desined  for  free,  non-commercial  software  creation. 
  1138. XIt is changeable and can be improved. The author would greatly appreciate 
  1139. Xany  advises, new  components  and  patches  of  the  existing  programs.
  1140. XCommercial  usage is  also  possible  with  participation of it's author.
  1141. X
  1142. X
  1143. X
  1144. X*/
  1145. X
  1146. X#include "FtpLibrary.h"
  1147. X#include <setjmp.h>
  1148. X#include <signal.h>
  1149. X
  1150. XSTATUS hook();
  1151. Xjmp_buf env;
  1152. X
  1153. XSTATUS FtpRetrTimeout (FTP * con , char * command ,
  1154. X               char *in , char * out,long timeout)
  1155. X{
  1156. X  FILE *o;
  1157. X  int c;
  1158. X
  1159. X  if (setjmp(env)!=0)
  1160. X    {
  1161. X      if (con->data!=NULL) fclose(con->data);
  1162. X      close(con->sock);
  1163. X      return EXIT(con,QUIT);
  1164. X    }
  1165. X
  1166. X  signal(SIGALRM,hook);
  1167. X  
  1168. X  if ( FtpData(con,command,in,"r") < 1 )
  1169. X    return EXIT(con,con->errno);
  1170. X
  1171. X  if ( (o=Ftpfopen(out,"w")) == NULL )
  1172. X    return EXIT(con,QUIT);
  1173. X  while ( (c=(alarm(timeout),FtpRead(con))) != EOF )
  1174. X    putc(c,o);
  1175. X  fclose(o);
  1176. X  return FtpClose(con);
  1177. X}
  1178. X
  1179. Xstatic hook()
  1180. X{
  1181. X  longjmp(env,1);
  1182. X}
  1183. X    
  1184. END_OF_FILE
  1185.   if test 1070 -ne `wc -c <'libftp/FtpRetrTimeout.c'`; then
  1186.     echo shar: \"'libftp/FtpRetrTimeout.c'\" unpacked with wrong size!
  1187.   fi
  1188.   # end of 'libftp/FtpRetrTimeout.c'
  1189. fi
  1190. if test -f 'libftp/FtpSendMessage.c' -a "${1}" != "-c" ; then 
  1191.   echo shar: Will not clobber existing file \"'libftp/FtpSendMessage.c'\"
  1192. else
  1193.   echo shar: Extracting \"'libftp/FtpSendMessage.c'\" \(708 characters\)
  1194.   sed "s/^X//" >'libftp/FtpSendMessage.c' <<'END_OF_FILE'
  1195. X/*
  1196. X              Library for ftpd clients.(libftp)
  1197. X            Copyright by Oleg Orel
  1198. X             All rights reserved.
  1199. X            
  1200. XThis  library is desined  for  free,  non-commercial  software  creation. 
  1201. XIt is changeable and can be improved. The author would greatly appreciate 
  1202. Xany  advises, new  components  and  patches  of  the  existing  programs.
  1203. XCommercial  usage is  also  possible  with  participation of it's author.
  1204. X
  1205. X
  1206. X
  1207. X*/
  1208. X
  1209. X#include "FtpLibrary.h"
  1210. X
  1211. XSTATUS FtpSendMessage(FTP *con,char * Message )
  1212. X{
  1213. X  if ( write ( con -> sock , Message , strlen (Message)) == -1 )
  1214. X    return QUIT;
  1215. X  if ( write ( con -> sock , "\015\012",2) == -1 )
  1216. X    return QUIT;
  1217. X  if ( con -> debug != NULL )
  1218. X    (*con->debug)(con,0,Message);
  1219. X  return 1;
  1220. X}
  1221. END_OF_FILE
  1222.   if test 708 -ne `wc -c <'libftp/FtpSendMessage.c'`; then
  1223.     echo shar: \"'libftp/FtpSendMessage.c'\" unpacked with wrong size!
  1224.   fi
  1225.   # end of 'libftp/FtpSendMessage.c'
  1226. fi
  1227. if test -f 'libftp/FtpStorTimeout.c' -a "${1}" != "-c" ; then 
  1228.   echo shar: Will not clobber existing file \"'libftp/FtpStorTimeout.c'\"
  1229. else
  1230.   echo shar: Extracting \"'libftp/FtpStorTimeout.c'\" \(1069 characters\)
  1231.   sed "s/^X//" >'libftp/FtpStorTimeout.c' <<'END_OF_FILE'
  1232. X/*
  1233. X              Library for ftpd clients.(libftp)
  1234. X            Copyright by Oleg Orel
  1235. X             All rights reserved.
  1236. X            
  1237. XThis  library is desined  for  free,  non-commercial  software  creation. 
  1238. XIt is changeable and can be improved. The author would greatly appreciate 
  1239. Xany  advises, new  components  and  patches  of  the  existing  programs.
  1240. XCommercial  usage is  also  possible  with  participation of it's author.
  1241. X
  1242. X
  1243. X
  1244. X*/
  1245. X
  1246. X#include "FtpLibrary.h"
  1247. X#include <setjmp.h>
  1248. X#include <signal.h>
  1249. X
  1250. XSTATUS hook();
  1251. Xjmp_buf env;
  1252. X
  1253. XSTATUS FtpStorTimeout (FTP * con , char * command ,
  1254. X               char *in , char * out,long timeout)
  1255. X{
  1256. X  FILE *i;
  1257. X  int c;
  1258. X
  1259. X  if (setjmp(env)!=0)
  1260. X    {
  1261. X      if (con->data!=NULL) fclose(con->data);
  1262. X      close(con->sock);
  1263. X      return EXIT(con,QUIT);
  1264. X    }
  1265. X
  1266. X  signal(SIGALRM,hook);
  1267. X  
  1268. X  if ( FtpData(con,command,out,"w") < 1 )
  1269. X    return EXIT(con,con->errno);
  1270. X
  1271. X  if ( (i=Ftpfopen(in,"r")) == NULL )
  1272. X    return EXIT(con,QUIT);
  1273. X  while ( (c=getc(i)) != EOF )
  1274. X    alarm(timeout),FtpWrite(con,c);
  1275. X  fclose(i);
  1276. X  return FtpClose(con);
  1277. X}
  1278. X
  1279. Xstatic hook()
  1280. X{
  1281. X  longjmp(env,1);
  1282. X}
  1283. X    
  1284. END_OF_FILE
  1285.   if test 1069 -ne `wc -c <'libftp/FtpStorTimeout.c'`; then
  1286.     echo shar: \"'libftp/FtpStorTimeout.c'\" unpacked with wrong size!
  1287.   fi
  1288.   # end of 'libftp/FtpStorTimeout.c'
  1289. fi
  1290. if test -f 'libftp/FtpType.c' -a "${1}" != "-c" ; then 
  1291.   echo shar: Will not clobber existing file \"'libftp/FtpType.c'\"
  1292. else
  1293.   echo shar: Extracting \"'libftp/FtpType.c'\" \(577 characters\)
  1294.   sed "s/^X//" >'libftp/FtpType.c' <<'END_OF_FILE'
  1295. X/*
  1296. X              Library for ftpd clients.(libftp)
  1297. X            Copyright by Oleg Orel
  1298. X             All rights reserved.
  1299. X            
  1300. XThis  library is desined  for  free,  non-commercial  software  creation. 
  1301. XIt is changeable and can be improved. The author would greatly appreciate 
  1302. Xany  advises, new  components  and  patches  of  the  existing  programs.
  1303. XCommercial  usage is  also  possible  with  participation of it's author.
  1304. X
  1305. X
  1306. X
  1307. X*/
  1308. X
  1309. X#include "FtpLibrary.h"
  1310. X
  1311. XSTATUS FtpType(FTP *ftp, char *type)
  1312. X{
  1313. X  STATUS p;
  1314. X  
  1315. X  if ((p=FtpCommand(ftp,"TYPE %s",type,200,EOF))>0)
  1316. X    ftp->mode=type[0];
  1317. X  return p;
  1318. X}
  1319. X
  1320. X  
  1321. END_OF_FILE
  1322.   if test 577 -ne `wc -c <'libftp/FtpType.c'`; then
  1323.     echo shar: \"'libftp/FtpType.c'\" unpacked with wrong size!
  1324.   fi
  1325.   # end of 'libftp/FtpType.c'
  1326. fi
  1327. if test -f 'libftp/FtpWrite.c' -a "${1}" != "-c" ; then 
  1328.   echo shar: Will not clobber existing file \"'libftp/FtpWrite.c'\"
  1329. else
  1330.   echo shar: Extracting \"'libftp/FtpWrite.c'\" \(819 characters\)
  1331.   sed "s/^X//" >'libftp/FtpWrite.c' <<'END_OF_FILE'
  1332. X/*
  1333. X              Library for ftpd clients.(libftp)
  1334. X            Copyright by Oleg Orel
  1335. X             All rights reserved.
  1336. X            
  1337. XThis  library is desined  for  free,  non-commercial  software  creation. 
  1338. XIt is changeable and can be improved. The author would greatly appreciate 
  1339. Xany  advises, new  components  and  patches  of  the  existing  programs.
  1340. XCommercial  usage is  also  possible  with  participation of it's author.
  1341. X
  1342. X
  1343. X
  1344. X*/
  1345. X
  1346. X#include "FtpLibrary.h"
  1347. X
  1348. Xint FtpWrite(FTP *con,char c)
  1349. X{
  1350. X  int i;
  1351. X  
  1352. X  if ( con -> mode == 'I' )
  1353. X    {
  1354. X      if (putc(c,con->data)==EOF)
  1355. X    return EXIT(con,QUIT);
  1356. X      else
  1357. X    return 0;
  1358. X    }
  1359. X  
  1360. X  if ( c == '\n' )
  1361. X    {
  1362. X      if (putc(Ctrl('M'),con->data)==EOF)
  1363. X    return EXIT(con,QUIT);
  1364. X      i=putc(Ctrl('J'),con->data);
  1365. X    }
  1366. X  else
  1367. X    i = putc ( c , con->data );
  1368. X  if (i==EOF) return EXIT(con,QUIT);
  1369. X  return i;
  1370. X}
  1371. END_OF_FILE
  1372.   if test 819 -ne `wc -c <'libftp/FtpWrite.c'`; then
  1373.     echo shar: \"'libftp/FtpWrite.c'\" unpacked with wrong size!
  1374.   fi
  1375.   # end of 'libftp/FtpWrite.c'
  1376. fi
  1377. if test -f 'libftp/Makefile' -a "${1}" != "-c" ; then 
  1378.   echo shar: Will not clobber existing file \"'libftp/Makefile'\"
  1379. else
  1380.   echo shar: Extracting \"'libftp/Makefile'\" \(1073 characters\)
  1381.   sed "s/^X//" >'libftp/Makefile' <<'END_OF_FILE'
  1382. X#
  1383. X#              Library for ftpd clients.(libftp)
  1384. X#            Copyright by Oleg Orel
  1385. X#             All rights reserved.
  1386. X#            
  1387. X#This  library is desined  for  free,  non-commercial  software  creation. 
  1388. X#It is changeable and can be improved. The author would greatly appreciate 
  1389. X#any  advises, new  components  and  patches  of  the  existing  programs.
  1390. X#Commercial  usage is  also  possible  with  participation of it's author.
  1391. X#
  1392. X
  1393. X
  1394. XLIBDIR        =    /usr/lib
  1395. XINCDIR        =    /usr/include 
  1396. XCFLAGS        =    
  1397. X
  1398. XOBJS          = FtpBye.o \
  1399. X        FtpType.o \
  1400. X        FtpClose.o \
  1401. X        FtpCommand.o \
  1402. X        FtpConnect.o \
  1403. X        FtpData.o \
  1404. X        FtpDebug.o \
  1405. X        FtpFopen.o \
  1406. X        FtpFull.o \
  1407. X        FtpGetHost.o \
  1408. X        FtpGetMessage.o \
  1409. X        FtpGetString.o \
  1410. X        FtpGood.o \
  1411. X        FtpInitMessage.o \
  1412. X        FtpLogin.o \
  1413. X        FtpMessage.o \
  1414. X        FtpMove.o \
  1415. X        FtpNumber.o \
  1416. X        FtpOpenDir.o \
  1417. X        FtpPort.o \
  1418. X        FtpPwd.o \
  1419. X        FtpRead.o \
  1420. X        FtpRetrTimeout.o \
  1421. X        FtpStorTimeout.o \
  1422. X        FtpSendMessage.o \
  1423. X        FtpWrite.o 
  1424. X
  1425. X
  1426. Xall:    libftp.a
  1427. X
  1428. Xlibftp.a: $(OBJS)
  1429. X    rm -f $@
  1430. X    ar cq $@ $* $(OBJS)
  1431. X    ranlib $@
  1432. X
  1433. X
  1434. Xinstall: all
  1435. X    cp libftp.a $(LIBDIR)
  1436. X    cp FtpLibrary.h $(INCDIR)
  1437. X
  1438. X
  1439. Xclean: 
  1440. X    rm -f libftp.a $(OBJS)
  1441. END_OF_FILE
  1442.   if test 1073 -ne `wc -c <'libftp/Makefile'`; then
  1443.     echo shar: \"'libftp/Makefile'\" unpacked with wrong size!
  1444.   fi
  1445.   # end of 'libftp/Makefile'
  1446. fi
  1447. if test -f 'libftp/examples/fcp.c' -a "${1}" != "-c" ; then 
  1448.   echo shar: Will not clobber existing file \"'libftp/examples/fcp.c'\"
  1449. else
  1450.   echo shar: Extracting \"'libftp/examples/fcp.c'\" \(906 characters\)
  1451.   sed "s/^X//" >'libftp/examples/fcp.c' <<'END_OF_FILE'
  1452. X/*
  1453. X              Library for ftpd clients.(libftp)
  1454. X            Copyright by Oleg Orel
  1455. X             All rights reserved.
  1456. X            
  1457. XThis  library is desined  for  free,  non-commercial  software  creation. 
  1458. XIt is changeable and can be improved. The author would greatly appreciate 
  1459. Xany  advises, new  components  and  patches  of  the  existing  programs.
  1460. XCommercial  usage is  also  possible  with  participation of it's author.
  1461. X
  1462. X
  1463. X
  1464. X*/
  1465. X
  1466. X#include "FtpLibrary.h"
  1467. X
  1468. Xmain(int a,char **b)
  1469. X{
  1470. X  FILE *out,*in;
  1471. X  int c;
  1472. X  extern int ftplib_debug;
  1473. X
  1474. X
  1475. X  FtplibDebug(1);
  1476. X
  1477. X  if ( a != 3 )
  1478. X    {
  1479. X      fprintf(stderr,
  1480. X          "Usage: %s node/user/pass:input-file node/user/pass:out-file\n",
  1481. X          b[0]);
  1482. X      exit(1);
  1483. X    }
  1484. X  
  1485. X  if ((in=FtpFullOpen(b[1],"rb"))==NULL)
  1486. X    perror(b[1]),exit(1);
  1487. X  if ((out=FtpFullOpen(b[2],"w"))==NULL)
  1488. X    perror(b[2]),exit(1);
  1489. X
  1490. X  
  1491. X  while((c=getc(in))!=EOF)
  1492. X    putc(c,out);
  1493. X  FtpFullClose(in);
  1494. X  FtpFullClose(out);
  1495. X}
  1496. END_OF_FILE
  1497.   if test 906 -ne `wc -c <'libftp/examples/fcp.c'`; then
  1498.     echo shar: \"'libftp/examples/fcp.c'\" unpacked with wrong size!
  1499.   fi
  1500.   # end of 'libftp/examples/fcp.c'
  1501. fi
  1502. if test -f 'libftp/examples/get.c' -a "${1}" != "-c" ; then 
  1503.   echo shar: Will not clobber existing file \"'libftp/examples/get.c'\"
  1504. else
  1505.   echo shar: Extracting \"'libftp/examples/get.c'\" \(882 characters\)
  1506.   sed "s/^X//" >'libftp/examples/get.c' <<'END_OF_FILE'
  1507. X/*
  1508. X              Library for ftpd clients.(libftp)
  1509. X            Copyright by Oleg Orel
  1510. X             All rights reserved.
  1511. X            
  1512. XThis  library is desined  for  free,  non-commercial  software  creation. 
  1513. XIt is changeable and can be improved. The author would greatly appreciate 
  1514. Xany  advises, new  components  and  patches  of  the  existing  programs.
  1515. XCommercial  usage is  also  possible  with  participation of it's author.
  1516. X
  1517. X
  1518. X
  1519. X*/
  1520. X
  1521. X#include "FtpLibrary.h"
  1522. X
  1523. Xmain(int a,char **b)
  1524. X{
  1525. X  FILE *out,*in;
  1526. X  String localfile;
  1527. X  int c;
  1528. X  
  1529. X
  1530. X  if ( a != 2 )
  1531. X    {
  1532. X      fprintf(stderr,
  1533. X          "Usage: %s node/user/pass:input-file\n",
  1534. X          b[0]);
  1535. X      exit(1);
  1536. X    }
  1537. X  if ((in=FtpFullOpen(b[1],"r"))==NULL)
  1538. X    perror(b[1]),exit(1);
  1539. X  sscanf(b[1],"%*[^:]:%s",localfile);
  1540. X  if ((out=fopen(localfile,"w"))==NULL)
  1541. X    perror(b[2]),exit(1);
  1542. X
  1543. X  while((c=getc(in))!=EOF)
  1544. X    putc(c,out);
  1545. X  FtpFullClose(in);
  1546. X  fclose(out);
  1547. X}
  1548. END_OF_FILE
  1549.   if test 882 -ne `wc -c <'libftp/examples/get.c'`; then
  1550.     echo shar: \"'libftp/examples/get.c'\" unpacked with wrong size!
  1551.   fi
  1552.   # end of 'libftp/examples/get.c'
  1553. fi
  1554. if test -f 'libftp/utils/Makefile' -a "${1}" != "-c" ; then 
  1555.   echo shar: Will not clobber existing file \"'libftp/utils/Makefile'\"
  1556. else
  1557.   echo shar: Extracting \"'libftp/utils/Makefile'\" \(134 characters\)
  1558.   sed "s/^X//" >'libftp/utils/Makefile' <<'END_OF_FILE'
  1559. XCFLAGS = -g -I.. -L..
  1560. XALL=ftptry
  1561. X
  1562. Xall: $(ALL)
  1563. X
  1564. Xftptry:    ftptry.o
  1565. X    cc $(CFLAGS) -o ftptry ftptry.o -lftp
  1566. X
  1567. Xclean: 
  1568. X    rm -f $(ALL) *~ *.o
  1569. X
  1570. END_OF_FILE
  1571.   if test 134 -ne `wc -c <'libftp/utils/Makefile'`; then
  1572.     echo shar: \"'libftp/utils/Makefile'\" unpacked with wrong size!
  1573.   fi
  1574.   # end of 'libftp/utils/Makefile'
  1575. fi
  1576. echo shar: End of archive 5 \(of 5\).
  1577. cp /dev/null ark5isdone
  1578. MISSING=""
  1579. for I in 1 2 3 4 5 ; do
  1580.     if test ! -f ark${I}isdone ; then
  1581.     MISSING="${MISSING} ${I}"
  1582.     fi
  1583. done
  1584. if test "${MISSING}" = "" ; then
  1585.     echo You have unpacked all 5 archives.
  1586.     rm -f ark[1-9]isdone
  1587. else
  1588.     echo You still must unpack the following archives:
  1589.     echo "        " ${MISSING}
  1590. fi
  1591. exit 0
  1592. exit 0 # Just in case...
  1593.