home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume38 / libftp / part01 < prev    next >
Encoding:
Text File  |  1993-07-12  |  37.4 KB  |  1,413 lines

  1. Newsgroups: comp.sources.misc
  2. From: orel@lpuds.oea.ihep.su (Oleg Orel)
  3. Subject: v38i052: libftp - A C library interface for the FTP protocol, Part01/01
  4. Message-ID: <1993Jul13.050434.18051@sparky.sterling.com>
  5. X-Md4-Signature: ff9953bd777924afd5e6e8cb3da28319
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Institute of High Energy Physics
  8. Date: Tue, 13 Jul 1993 05:04:34 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: orel@lpuds.oea.ihep.su (Oleg Orel)
  12. Posting-number: Volume 38, Issue 52
  13. Archive-name: libftp/part01
  14. Environment: UNIX
  15.  
  16. libftp is a simple C interface to the FTP protocol, i.e. a library with 
  17. routines like FtpConnect(host), FtpLogin(user, passw,acct), FtpGet(File),
  18. FtpDir(filespec), FtpDebug(handler), FtpFullOpen(remote or local,read or 
  19. write), FtpError(handler) and many other functions.
  20.  
  21.  ---------------------------------------------------------------------------
  22.  | Oleg Orel, Russia, Protvino       |   orel@lpuds.oea.ihep.su            |
  23.  | Institute of High Energy Physics  |   Home Phone: 49106                 |
  24.  ---------------------------------------------------------------------------
  25. #! /bin/sh
  26. # This is a shell archive.  Remove anything before this line, then feed it
  27. # into a shell via "sh file" or similar.  To overwrite existing files,
  28. # type "sh file -c".
  29. # Contents:  FtpBye.c FtpClose.c FtpCommand.c FtpConnect.c FtpData.c
  30. #   FtpDebug.c FtpFull.c FtpGetMessage.c FtpGetString.c FtpGood.c
  31. #   FtpInitMessage.c FtpLibrary.h FtpLogin.c FtpMessage.c FtpMove.c
  32. #   FtpNumber.c FtpOpenDir.c FtpPort.c FtpPut.c FtpPwd.c FtpRead.c
  33. #   FtpRetr.c FtpSendMessage.c FtpWrite.c Makefile fcp.c get.c
  34. #   libftp.3 test.c
  35. # Wrapped by kent@sparky on Sun Jul 11 18:43:44 CDT 1993
  36. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  37. echo If this archive is complete, you will see the following message:
  38. echo '          "shar: End of archive 1 (of 1)."'
  39. if test -f 'FtpBye.c' -a "${1}" != "-c" ; then 
  40.   echo shar: Will not clobber existing file \"'FtpBye.c'\"
  41. else
  42.   echo shar: Extracting \"'FtpBye.c'\" \(336 characters\)
  43.   sed "s/^X//" >'FtpBye.c' <<'END_OF_FILE'
  44. X#include "FtpLibrary.h"
  45. X
  46. XSTATUS FtpBye(FTP *sock)
  47. X{
  48. X  String S1;
  49. X  int i;
  50. X  
  51. X  if ( FtpSendMessage(sock,"QUIT") == QUIT )
  52. X    return EXIT(sock,QUIT);
  53. X
  54. X  if ( (i=FtpGetMessage(sock,S1)) == QUIT )
  55. X    return EXIT(sock,QUIT);
  56. X
  57. X  if ( i != 221 )
  58. X    return EXIT(sock,-i);
  59. X
  60. X  close(sock->sock);
  61. X  free(sock);
  62. X  return EXIT(sock,i);
  63. X}
  64. X      
  65. END_OF_FILE
  66.   if test 336 -ne `wc -c <'FtpBye.c'`; then
  67.     echo shar: \"'FtpBye.c'\" unpacked with wrong size!
  68.   fi
  69.   # end of 'FtpBye.c'
  70. fi
  71. if test -f 'FtpClose.c' -a "${1}" != "-c" ; then 
  72.   echo shar: Will not clobber existing file \"'FtpClose.c'\"
  73. else
  74.   echo shar: Extracting \"'FtpClose.c'\" \(239 characters\)
  75.   sed "s/^X//" >'FtpClose.c' <<'END_OF_FILE'
  76. X#include "FtpLibrary.h"
  77. X
  78. XSTATUS FtpClose(FTP *sock)
  79. X{
  80. X  int i;
  81. X  String S1;
  82. X  
  83. X  fclose(sock->data);
  84. X
  85. X  if ((i=FtpGetMessage(sock,S1))==QUIT)
  86. X    return EXIT(sock,QUIT);
  87. X  if ( i != 226 )
  88. X    return EXIT(sock,-i);
  89. X  return EXIT(sock,i);
  90. X}
  91. END_OF_FILE
  92.   if test 239 -ne `wc -c <'FtpClose.c'`; then
  93.     echo shar: \"'FtpClose.c'\" unpacked with wrong size!
  94.   fi
  95.   # end of 'FtpClose.c'
  96. fi
  97. if test -f 'FtpCommand.c' -a "${1}" != "-c" ; then 
  98.   echo shar: Will not clobber existing file \"'FtpCommand.c'\"
  99. else
  100.   echo shar: Extracting \"'FtpCommand.c'\" \(391 characters\)
  101.   sed "s/^X//" >'FtpCommand.c' <<'END_OF_FILE'
  102. X#include "FtpLibrary.h"
  103. X
  104. XSTATUS FtpCommand(FTP * con , char * command , char * param , int list)
  105. X{
  106. X  String S1;
  107. X  int i;
  108. X  
  109. X  sprintf(S1,command,param);
  110. X
  111. X  if ( FtpSendMessage(con,S1) == QUIT )
  112. X    return EXIT(con,QUIT);
  113. X  
  114. X  if  ( (i=FtpGetMessage(con,S1)) == QUIT )
  115. X    return EXIT(con,QUIT);
  116. X  
  117. X  if ( ! FtpGood1 ( i , &list ))
  118. X    return EXIT(con,-i);
  119. X
  120. X  return EXIT(con,i);
  121. X}
  122. X  
  123. X  
  124. X   
  125. END_OF_FILE
  126.   if test 391 -ne `wc -c <'FtpCommand.c'`; then
  127.     echo shar: \"'FtpCommand.c'\" unpacked with wrong size!
  128.   fi
  129.   # end of 'FtpCommand.c'
  130. fi
  131. if test -f 'FtpConnect.c' -a "${1}" != "-c" ; then 
  132.   echo shar: Will not clobber existing file \"'FtpConnect.c'\"
  133. else
  134.   echo shar: Extracting \"'FtpConnect.c'\" \(1267 characters\)
  135.   sed "s/^X//" >'FtpConnect.c' <<'END_OF_FILE'
  136. X#include "FtpLibrary.h"
  137. X
  138. XSTATUS FtpConnect(FTP **con,char * hostname)
  139. X{
  140. X  struct sockaddr_in unit;
  141. X  register struct hostent *host;
  142. X  register struct servent *service;
  143. X  register int sock;
  144. X  String S1;
  145. X  STATUS x;
  146. X  
  147. X  *con = ( FTP * ) malloc ( sizeof (FTP));
  148. X  
  149. X  if ((host=gethostbyname(hostname))==0)
  150. X    return EXIT((*con),QUIT);
  151. X  if ((service=(struct servent *) getservbyname("ftp","tcp"))==0)
  152. X    return EXIT((*con),QUIT);
  153. X  
  154. X  unit.sin_family = host -> h_addrtype;
  155. X  
  156. X  bcopy(host-> h_addr_list[0],&unit.sin_addr,host->h_length);
  157. X  if ( ( sock = socket ( unit.sin_family , SOCK_STREAM , 0)) < 0)
  158. X    return EXIT((*con),QUIT);
  159. X
  160. X  unit.sin_port = service -> s_port;
  161. X
  162. X  while ( connect ( sock , &unit , sizeof unit ) < 0 )
  163. X    {
  164. X      host -> h_addr_list ++;
  165. X      bcopy(host -> h_addr_list[0],&unit,host->h_length);
  166. X      close(sock);
  167. X      if ( ( sock = socket ( unit.sin_family , SOCK_STREAM , 0)) < 0)
  168. X    return EXIT((*con),QUIT);
  169. X    }
  170. X  
  171. X  (*con) -> sock = sock;
  172. X  (*con) -> mode = 'A';
  173. X  (*con) -> data = 0;
  174. X  (*con) -> func = NULL;
  175. X  (*con) -> debug = NULL;
  176. X  
  177. X  if ( (x=FtpGetMessage(*con,S1)) == QUIT )
  178. X    return EXIT((*con),QUIT);
  179. X  if ( ! FtpGood(x,120,220,EOF))
  180. X    {
  181. X      close(sock);
  182. X      return EXIT((*con),-x);
  183. X    }
  184. X  return EXIT((*con),x);
  185. X}
  186. END_OF_FILE
  187.   if test 1267 -ne `wc -c <'FtpConnect.c'`; then
  188.     echo shar: \"'FtpConnect.c'\" unpacked with wrong size!
  189.   fi
  190.   # end of 'FtpConnect.c'
  191. fi
  192. if test -f 'FtpData.c' -a "${1}" != "-c" ; then 
  193.   echo shar: Will not clobber existing file \"'FtpData.c'\"
  194. else
  195.   echo shar: Extracting \"'FtpData.c'\" \(1591 characters\)
  196.   sed "s/^X//" >'FtpData.c' <<'END_OF_FILE'
  197. X#include "FtpLibrary.h"
  198. X
  199. XSTATUS FtpData(FTP * con,char * command , char * file ,char * mode)
  200. X{
  201. X  struct sockaddr_in data,from;
  202. X  register struct hostent *host;
  203. X  String hostname,cmd;
  204. X  int NewSocket,len=sizeof(data),one=1,fromlen=sizeof(from),i;
  205. X  char *a,*b;
  206. X
  207. X  FREE(data);
  208. X  FREE(from);
  209. X  
  210. X  if ( gethostname( hostname , sizeof hostname ) == -1 )
  211. X    return EXIT(con,QUIT);
  212. X  
  213. X  if ((host=(struct hostent *)gethostbyname(hostname))==0)
  214. X    return EXIT(con,QUIT);
  215. X  
  216. X  data.sin_family = host -> h_addrtype;
  217. X  
  218. X  bcopy(host-> h_addr_list[0],&data.sin_addr,host->h_length);
  219. X        
  220. X  if ((NewSocket = socket ( AF_INET  , SOCK_STREAM , 0 ))<0)
  221. X    return EXIT(con,QUIT);
  222. X
  223. X  if ( setsockopt ( NewSocket , SOL_SOCKET , SO_REUSEADDR ,
  224. X            &one , sizeof one ) < 0 )
  225. X    {
  226. X      close(NewSocket);
  227. X      return EXIT ( con,QUIT );
  228. X    }
  229. X
  230. X  data.sin_port = 0 ;
  231. X
  232. X  if ( bind ( NewSocket , &data , sizeof data ) < 0 )
  233. X    return EXIT(con,QUIT);
  234. X
  235. X  if ( getsockname ( NewSocket , &data , &len ) < 0 )
  236. X    return EXIT(con,QUIT);
  237. X
  238. X  if ( listen ( NewSocket , 1 ) < 0 )
  239. X    return EXIT(con,QUIT);
  240. X
  241. X  a = ( char * ) & data.sin_addr;
  242. X  b = ( char * ) & data.sin_port;
  243. X
  244. X  if ( (i=FtpPort(con,CUT(a[0]),CUT(a[1]),CUT(a[2]),
  245. X          CUT(a[3]),CUT(b[0]),CUT(b[1]))) < 1 )
  246. X    return i;
  247. X  
  248. X  i = FtpCommand ( con , command , file , 
  249. X          120 , 150 , 200 , 125 , 250 , EOF );
  250. X  if ( i < 1 )
  251. X    return i;
  252. X
  253. X  if (( NewSocket = accept (NewSocket , &from , &fromlen )) < 0)
  254. X    {
  255. X      close(NewSocket);
  256. X      return EXIT(con,QUIT);
  257. X    }
  258. X
  259. X  con -> data = fdopen ( NewSocket , mode );
  260. X  con -> ch = EOF;
  261. X  
  262. X  return i;
  263. X}
  264. X
  265. X
  266. X
  267. X
  268. X
  269. END_OF_FILE
  270.   if test 1591 -ne `wc -c <'FtpData.c'`; then
  271.     echo shar: \"'FtpData.c'\" unpacked with wrong size!
  272.   fi
  273.   # end of 'FtpData.c'
  274. fi
  275. if test -f 'FtpDebug.c' -a "${1}" != "-c" ; then 
  276.   echo shar: Will not clobber existing file \"'FtpDebug.c'\"
  277. else
  278.   echo shar: Extracting \"'FtpDebug.c'\" \(400 characters\)
  279.   sed "s/^X//" >'FtpDebug.c' <<'END_OF_FILE'
  280. X#include "FtpLibrary.h"
  281. X
  282. XSTATUS FtpDebug(FTP *ftp)
  283. X{
  284. X  STATUS FtpDebugDebug(),
  285. X         FtpDebugError();
  286. X
  287. X  FtpSetDebugHandler(ftp,FtpDebugDebug);
  288. X  FtpSetErrorHandler(ftp,FtpDebugError);
  289. X}
  290. X
  291. XFtpDebugDebug(FTP *ftp,int n, char * Message)
  292. X{
  293. X  fprintf(stderr,"DEBUG:: %s\n",Message);
  294. X  return 1;
  295. X}
  296. X
  297. XFtpDebugError(FTP *ftp,int n, char * Message)
  298. X{
  299. X  fprintf(stderr,"Abort:: %s\n",Message);
  300. X  exit(1);
  301. X}
  302. X
  303. END_OF_FILE
  304.   if test 400 -ne `wc -c <'FtpDebug.c'`; then
  305.     echo shar: \"'FtpDebug.c'\" unpacked with wrong size!
  306.   fi
  307.   # end of 'FtpDebug.c'
  308. fi
  309. if test -f 'FtpFull.c' -a "${1}" != "-c" ; then 
  310.   echo shar: Will not clobber existing file \"'FtpFull.c'\"
  311. else
  312.   echo shar: Extracting \"'FtpFull.c'\" \(1594 characters\)
  313.   sed "s/^X//" >'FtpFull.c' <<'END_OF_FILE'
  314. X#include "FtpLibrary.h"
  315. X
  316. Xstatic FTP *ftp_table[256];
  317. Xstatic syntax();
  318. X
  319. XFILE * FtpFullOpen(char * file , char * mode )
  320. X{
  321. X  FTP *ftp;
  322. X  FILE *tmp;
  323. X  String Host,User,Passwd,RemoteFile;
  324. X  STATUS i;
  325. X
  326. X  if ( ! syntax (file,Host,User,Passwd,RemoteFile))
  327. X    {
  328. X      tmp=fopen(file,mode);
  329. X      ftp_table[fileno(tmp)] = NULL;
  330. X      return tmp;
  331. X    }
  332. X  if ( (i=FtpLogin(&ftp,Host,User,Passwd,NULL)) < 1 )
  333. X    return NULL;
  334. X
  335. X  FtpBinary(ftp);
  336. X
  337. X  switch(mode[0])
  338. X    {
  339. X    case 'r': 
  340. X    if (FtpOpenRead(ftp,RemoteFile)<1) 
  341. X      return NULL;
  342. X    ftp_table[fileno(ftp->data)] = ftp;
  343. X    return ftp->data;
  344. X    case 'w':
  345. X    if (FtpOpenWrite(ftp,RemoteFile)<1)
  346. X      return NULL;
  347. X    ftp_table[fileno(ftp->data)] = ftp;
  348. X    return ftp->data;
  349. X    case 'a':
  350. X    if (FtpOpenAppend(ftp,RemoteFile)<1)
  351. X      return NULL;
  352. X    ftp_table[fileno(ftp->data)] = ftp;
  353. X    return ftp->data;
  354. X    }
  355. X}
  356. X
  357. XSTATUS   FtpFullClose(FILE *f)
  358. X{
  359. X  FTP *ftp=ftp_table[fileno(f)];
  360. X  if (ftp == NULL)
  361. X    return fclose(f);
  362. X  FtpClose(ftp);
  363. X  return FtpBye(ftp);
  364. X}
  365. X
  366. Xstatic syntax ( source , host , user , passwd , file)
  367. XString source,host,user,passwd,file;
  368. X{
  369. X  char *in,*out;
  370. X  host[0] = user[0] = passwd[0] = file[0] = '\0';
  371. X  for ( in = source , out = host;
  372. X       *in !='\0' && *in != '/' ;
  373. X       *out++ = *in++);
  374. X  if ( *in == '\0' ) return 0;
  375. X  in++;
  376. X  for ( out = user;
  377. X       *in !='\0' && *in != '/' ;
  378. X       *out++ = *in++);
  379. X  if ( *in == '\0' ) return 0;
  380. X  in++;
  381. X  for ( out = passwd;
  382. X       *in !='\0' && *in != ':' ;
  383. X       *out++ = *in++);
  384. X  if ( *in == '\0' ) return 0;
  385. X  in++;
  386. X  for ( out = file;
  387. X       *in !='\0';
  388. X       *out++ = *in++);
  389. X  return 1;
  390. X}
  391. X  
  392. END_OF_FILE
  393.   if test 1594 -ne `wc -c <'FtpFull.c'`; then
  394.     echo shar: \"'FtpFull.c'\" unpacked with wrong size!
  395.   fi
  396.   # end of 'FtpFull.c'
  397. fi
  398. if test -f 'FtpGetMessage.c' -a "${1}" != "-c" ; then 
  399.   echo shar: Will not clobber existing file \"'FtpGetMessage.c'\"
  400. else
  401.   echo shar: Extracting \"'FtpGetMessage.c'\" \(559 characters\)
  402.   sed "s/^X//" >'FtpGetMessage.c' <<'END_OF_FILE'
  403. X#include "FtpLibrary.h"
  404. X
  405. Xextern char * FtpMessageList[];
  406. X
  407. Xint FtpGetMessage(FTP *con , char * Message )
  408. X{
  409. X  int i=0,n;
  410. X  
  411. X  while(1)
  412. X    {
  413. X      if ( read ( con -> sock , &Message[i] , 1 ) != 1 )
  414. X    return QUIT;
  415. X      if ( Message[i] == Ctrl('J') && Message[i-1] == Ctrl('M'))
  416. X    break;
  417. X      i++;
  418. X    }
  419. X  
  420. X  Message[i-1] = 0;
  421. X  FtpInitMessageList();
  422. X  FtpMessageList[n=FtpNumber(Message)] =
  423. X    ( char * ) malloc ( strlen(Message) + 1);
  424. X  strcpy(FtpMessageList[n] , Message );
  425. X  if ( con -> debug != NULL )
  426. X    (*con->debug)(con,n,Message);
  427. X  return n;
  428. X}
  429. X      
  430. END_OF_FILE
  431.   if test 559 -ne `wc -c <'FtpGetMessage.c'`; then
  432.     echo shar: \"'FtpGetMessage.c'\" unpacked with wrong size!
  433.   fi
  434.   # end of 'FtpGetMessage.c'
  435. fi
  436. if test -f 'FtpGetString.c' -a "${1}" != "-c" ; then 
  437.   echo shar: Will not clobber existing file \"'FtpGetString.c'\"
  438. else
  439.   echo shar: Extracting \"'FtpGetString.c'\" \(254 characters\)
  440.   sed "s/^X//" >'FtpGetString.c' <<'END_OF_FILE'
  441. X#include "FtpLibrary.h"
  442. X
  443. XSTATUS FtpGetString(FTP *con ,char * str )
  444. X{
  445. X  int i=0;
  446. X  while ( (str[i]=FtpRead(con)) != '\n' && str[i] != EOF ) i++;
  447. X  if ( str[i] != EOF )
  448. X    { 
  449. X      str[i] = '\0';
  450. X      return i;
  451. X    }
  452. X  str[i] = '\0';
  453. X  return EOF;
  454. X}
  455. X  
  456. END_OF_FILE
  457.   if test 254 -ne `wc -c <'FtpGetString.c'`; then
  458.     echo shar: \"'FtpGetString.c'\" unpacked with wrong size!
  459.   fi
  460.   # end of 'FtpGetString.c'
  461. fi
  462. if test -f 'FtpGood.c' -a "${1}" != "-c" ; then 
  463.   echo shar: Will not clobber existing file \"'FtpGood.c'\"
  464. else
  465.   echo shar: Extracting \"'FtpGood.c'\" \(228 characters\)
  466.   sed "s/^X//" >'FtpGood.c' <<'END_OF_FILE'
  467. X#include "FtpLibrary.h"
  468. X
  469. XSTATUS FtpGood(int n,int list)
  470. X{
  471. X  return FtpGood1(n,&list);
  472. X}
  473. X
  474. X
  475. XSTATUS FtpGood1(int Number,int * Answer)
  476. X{
  477. X  int i=0;
  478. X  while(Answer[i]!=EOF)
  479. X      if ( Number == Answer[i++] )
  480. X    return 1;
  481. X  return 0;
  482. X}
  483. END_OF_FILE
  484.   if test 228 -ne `wc -c <'FtpGood.c'`; then
  485.     echo shar: \"'FtpGood.c'\" unpacked with wrong size!
  486.   fi
  487.   # end of 'FtpGood.c'
  488. fi
  489. if test -f 'FtpInitMessage.c' -a "${1}" != "-c" ; then 
  490.   echo shar: Will not clobber existing file \"'FtpInitMessage.c'\"
  491. else
  492.   echo shar: Extracting \"'FtpInitMessage.c'\" \(215 characters\)
  493.   sed "s/^X//" >'FtpInitMessage.c' <<'END_OF_FILE'
  494. X#include "FtpLibrary.h"
  495. X
  496. Xchar * FtpMessageList[1000];
  497. X
  498. XSTATUS FtpInitMessageList()
  499. X{
  500. X  int i;
  501. X  static u = 0;
  502. X  
  503. X  if ( u )
  504. X    return 1;
  505. X
  506. X  u = 1;
  507. X
  508. X  for (i=0;i<1000;i++)
  509. X    FtpMessageList[i]=NULL;
  510. X
  511. X  return 1;
  512. X}
  513. END_OF_FILE
  514.   if test 215 -ne `wc -c <'FtpInitMessage.c'`; then
  515.     echo shar: \"'FtpInitMessage.c'\" unpacked with wrong size!
  516.   fi
  517.   # end of 'FtpInitMessage.c'
  518. fi
  519. if test -f 'FtpLibrary.h' -a "${1}" != "-c" ; then 
  520.   echo shar: Will not clobber existing file \"'FtpLibrary.h'\"
  521. else
  522.   echo shar: Extracting \"'FtpLibrary.h'\" \(2824 characters\)
  523.   sed "s/^X//" >'FtpLibrary.h' <<'END_OF_FILE'
  524. X#include <stdio.h>
  525. X#include <sys/types.h>
  526. X#include <sys/socket.h>
  527. X#include <arpa/ftp.h>
  528. X#include <netinet/in.h>
  529. X#include <netdb.h>
  530. X
  531. X#define EXIT(con,e) \
  532. X  ({ con -> errno = e;  \
  533. X     if ( (con->func != NULL) && (e < 0) ) \
  534. X       (*(con->func))(con,e,FtpMessage(e));\
  535. X     e;\
  536. X  })
  537. X   
  538. X#define QUIT 0
  539. X#define Ctrl(x) ((x) - '@')
  540. X#define FREE(x) memset ( &x , '\0' , sizeof x )
  541. X#define CUT(x) ((x)&0xff)
  542. X
  543. Xtypedef int STATUS;
  544. Xtypedef char String[256];
  545. Xtypedef int Answers[];
  546. X
  547. Xtypedef struct
  548. X{
  549. X  int sock;
  550. X  FILE *data;
  551. X  char mode;
  552. X  int errno;
  553. X  int ch;
  554. X  STATUS (*func)();
  555. X  STATUS (*debug)();
  556. X} FTP;
  557. X
  558. X#define FtpSetErrorHandler(con,f) con->func = f;
  559. X#define FtpSetDebugHandler(con,f) con->debug = f; 
  560. X
  561. X#define FtpAccount(ftp,acc)       FtpCommand(ftp,"ACCT %s",acc,230,EOF)
  562. X#define FtpUser(ftp,user)         FtpCommand(ftp,"USER %s",user,230,331,332,EOF)
  563. X#define FtpPassword(ftp,pas)      FtpCommand(ftp,"PASS %s",pas,230,332,EOF)
  564. X#define FtpType(ftp,type)         FtpCommand(ftp,"TYPE %c",type,200,EOF)
  565. X#define FtpChdir(ftp,dir)         FtpCommand(ftp,"CWD %s",dir,200,250,EOF)
  566. X#define FtpMkdir(ftp,dir)         FtpCommand(ftp,"MKD %s",dir,200,257,EOF)
  567. X#define FtpRm(ftp,dir)            FtpCommand(ftp,"DELE %s",dir,200,250,EOF)
  568. X#define FtpGetFile(ftp,file)      FtpCommand(ftp,"RETR %s",file,\
  569. X                        200,125,150,250,EOF)
  570. X#define FtpPutFile(ftp,file)      FtpCommand(ftp,"STOR %s",file,\
  571. X                       200,125,150,250,EOF)
  572. X#define FtpAscii(ftp)             FtpType(ftp,'A')
  573. X#define FtpBinary(ftp)            FtpType(ftp,'I')
  574. X#define FtpOpenRead(ftp,file)     FtpData(ftp,"RETR %s",file,"r")
  575. X#define FtpOpenWrite(ftp,file)    FtpData(ftp,"STOR %s",file,"w")
  576. X#define FtpOpenAppend(ftp,file)   FtpData(ftp,"APPE %s",file,"r")
  577. X#define FtpDirectory(ftp,pat,out) FtpRetr(ftp,"LIST %s",pat,out)
  578. X#define FtpDir(ftp,out)           FtpRetr(ftp,"LIST","",out)
  579. X#define FtpGet(ftp,in,out)        FtpRetr(ftp,"RETR %s",in,out)
  580. X
  581. X
  582. XFILE
  583. X  * FtpFullOpen(char * file,char * mode );
  584. XSTATUS
  585. X  FtpBye (FTP * con),
  586. X  FtpClose ( FTP *),
  587. X  FtpConnect ( FTP **con,char *hostname),
  588. X  FtpFullClose(FILE *),
  589. X  FtpRetr ( FTP *con , char * command , char * inp , char * out),
  590. X  FtpGetString ( FTP * con , char * str ),
  591. X  FtpDebug ( FTP * con ),
  592. X  FtpInitMessageList(),
  593. X  FtpLogin ( FTP **con, char * host , char * user , char * pass , char * acct),
  594. X  FtpMove ( FTP *con,char * old,char *new),
  595. X  FtpData( FTP * con , char * command , char * param , char * mode ),
  596. X  FtpPort ( FTP *con ,int ,int ,int ,int ,int ,int ),
  597. X  FtpPut ( FTP * con , char * inp , char * out),
  598. X  FtpRead ( FTP * con),
  599. X  FtpOpenDir( FTP * con , char * files ),
  600. X  FtpSendMessage( FTP * con , char * Message ),
  601. X  FtpWrite ( FTP * con , char c);
  602. X
  603. Xint
  604. X  FtpGetMessage( FTP * con , char * Message),
  605. X  FtpNumber ( char * Message );
  606. X
  607. Xchar 
  608. X  *FtpPwd(FTP *con),
  609. X  *FtpMessage(int Number);
  610. X
  611. X
  612. END_OF_FILE
  613.   if test 2824 -ne `wc -c <'FtpLibrary.h'`; then
  614.     echo shar: \"'FtpLibrary.h'\" unpacked with wrong size!
  615.   fi
  616.   # end of 'FtpLibrary.h'
  617. fi
  618. if test -f 'FtpLogin.c' -a "${1}" != "-c" ; then 
  619.   echo shar: Will not clobber existing file \"'FtpLogin.c'\"
  620. else
  621.   echo shar: Extracting \"'FtpLogin.c'\" \(480 characters\)
  622.   sed "s/^X//" >'FtpLogin.c' <<'END_OF_FILE'
  623. X#include "FtpLibrary.h"
  624. X
  625. XSTATUS FtpLogin ( FTP ** con, char * host , char * user , 
  626. X          char * password , char * account)
  627. X{
  628. X  STATUS x;
  629. X  
  630. X  if ( (x=FtpConnect(con,host)) < 1)
  631. X    return x;
  632. X  if ( (x=FtpUser(*con,user)) < 1)
  633. X    return x;
  634. X  if ( x==230 )
  635. X    return x;
  636. X  if ( x==332)
  637. X    {
  638. X      if ( account == NULL )
  639. X    return EXIT((*con),x);
  640. X      if ( (x=FtpAccount( *con , account )) < 1 )
  641. X    return x;
  642. X      if ( x==230 )
  643. X    return x;
  644. X    }
  645. X  return FtpPassword(*con,password);
  646. X}
  647. END_OF_FILE
  648.   if test 480 -ne `wc -c <'FtpLogin.c'`; then
  649.     echo shar: \"'FtpLogin.c'\" unpacked with wrong size!
  650.   fi
  651.   # end of 'FtpLogin.c'
  652. fi
  653. if test -f 'FtpMessage.c' -a "${1}" != "-c" ; then 
  654.   echo shar: Will not clobber existing file \"'FtpMessage.c'\"
  655. else
  656.   echo shar: Extracting \"'FtpMessage.c'\" \(255 characters\)
  657.   sed "s/^X//" >'FtpMessage.c' <<'END_OF_FILE'
  658. X#include "FtpLibrary.h"
  659. X
  660. Xextern char * FtpMessageList[];
  661. X
  662. Xchar *FtpMessage(int number)
  663. X{
  664. X  FtpInitMessageList();
  665. X  if ( number == 0 )
  666. X    return "I/O Error , use perror";
  667. X  return (FtpMessageList[abs(number)]==NULL)?
  668. X    "":FtpMessageList[abs(number)];
  669. X}
  670. END_OF_FILE
  671.   if test 255 -ne `wc -c <'FtpMessage.c'`; then
  672.     echo shar: \"'FtpMessage.c'\" unpacked with wrong size!
  673.   fi
  674.   # end of 'FtpMessage.c'
  675. fi
  676. if test -f 'FtpMove.c' -a "${1}" != "-c" ; then 
  677.   echo shar: Will not clobber existing file \"'FtpMove.c'\"
  678. else
  679.   echo shar: Extracting \"'FtpMove.c'\" \(241 characters\)
  680.   sed "s/^X//" >'FtpMove.c' <<'END_OF_FILE'
  681. X#include "FtpLibrary.h"
  682. X
  683. XSTATUS FtpMove(FTP *con,char * oldname , char * newname )
  684. X{
  685. X  STATUS i;
  686. X
  687. X  if ((i=FtpCommand(con,"RNFR %s",oldname,200,350,EOF)) > 1 )
  688. X    return FtpCommand(con,"RNTO %s",newname,200,250,EOF);
  689. X  else
  690. X    return i;
  691. X}
  692. END_OF_FILE
  693.   if test 241 -ne `wc -c <'FtpMove.c'`; then
  694.     echo shar: \"'FtpMove.c'\" unpacked with wrong size!
  695.   fi
  696.   # end of 'FtpMove.c'
  697. fi
  698. if test -f 'FtpNumber.c' -a "${1}" != "-c" ; then 
  699.   echo shar: Will not clobber existing file \"'FtpNumber.c'\"
  700. else
  701.   echo shar: Extracting \"'FtpNumber.c'\" \(153 characters\)
  702.   sed "s/^X//" >'FtpNumber.c' <<'END_OF_FILE'
  703. X#include "FtpLibrary.h"
  704. X
  705. Xint FtpNumber(char *Message)
  706. X{
  707. X  return (Message[0] - '0') * 100 +
  708. X         (Message[1] - '0') * 10  +
  709. X     (Message[2] - '0') ;
  710. X}
  711. END_OF_FILE
  712.   if test 153 -ne `wc -c <'FtpNumber.c'`; then
  713.     echo shar: \"'FtpNumber.c'\" unpacked with wrong size!
  714.   fi
  715.   # end of 'FtpNumber.c'
  716. fi
  717. if test -f 'FtpOpenDir.c' -a "${1}" != "-c" ; then 
  718.   echo shar: Will not clobber existing file \"'FtpOpenDir.c'\"
  719. else
  720.   echo shar: Extracting \"'FtpOpenDir.c'\" \(248 characters\)
  721.   sed "s/^X//" >'FtpOpenDir.c' <<'END_OF_FILE'
  722. X#include "FtpLibrary.h"
  723. X
  724. XSTATUS FtpOpenDir(FTP * con,char * file)
  725. X{
  726. X  char * command;
  727. X
  728. X  if ( file == NULL || *file == '\0' )
  729. X    command = "NLST";
  730. X  else
  731. X    sprintf(command,"NLST %s",file);
  732. X
  733. X  return FtpCommand(con,command,"",120,150,200,EOF);
  734. X}
  735. END_OF_FILE
  736.   if test 248 -ne `wc -c <'FtpOpenDir.c'`; then
  737.     echo shar: \"'FtpOpenDir.c'\" unpacked with wrong size!
  738.   fi
  739.   # end of 'FtpOpenDir.c'
  740. fi
  741. if test -f 'FtpPort.c' -a "${1}" != "-c" ; then 
  742.   echo shar: Will not clobber existing file \"'FtpPort.c'\"
  743. else
  744.   echo shar: Extracting \"'FtpPort.c'\" \(371 characters\)
  745.   sed "s/^X//" >'FtpPort.c' <<'END_OF_FILE'
  746. X#include "FtpLibrary.h"
  747. X
  748. XSTATUS FtpPort(FTP *con,int a,int b,int c,int d,int e,int f)
  749. X{
  750. X  String cmd;
  751. X  int i;
  752. X
  753. X  sprintf(cmd,"PORT %d,%d,%d,%d,%d,%d",a,b,c,d,e,f);
  754. X  if ( FtpSendMessage(con,cmd) == QUIT)
  755. X    return QUIT;
  756. X  if ( (i=FtpGetMessage(con,cmd)) == QUIT)
  757. X    return QUIT;
  758. X  
  759. X  if ( ! FtpGood ( i , 200 , EOF ))
  760. X    return EXIT(con,-i);
  761. X
  762. X  return EXIT(con,i);
  763. X}
  764. END_OF_FILE
  765.   if test 371 -ne `wc -c <'FtpPort.c'`; then
  766.     echo shar: \"'FtpPort.c'\" unpacked with wrong size!
  767.   fi
  768.   # end of 'FtpPort.c'
  769. fi
  770. if test -f 'FtpPut.c' -a "${1}" != "-c" ; then 
  771.   echo shar: Will not clobber existing file \"'FtpPut.c'\"
  772. else
  773.   echo shar: Extracting \"'FtpPut.c'\" \(313 characters\)
  774.   sed "s/^X//" >'FtpPut.c' <<'END_OF_FILE'
  775. X#include "FtpLibrary.h"
  776. X
  777. XSTATUS FtpPut(FTP * con , char * in , char * out )
  778. X{
  779. X  FILE *o;
  780. X  int c;
  781. X  
  782. X  if ( FtpOpenWrite(con,out) < 1 )
  783. X    return con->errno;
  784. X
  785. X  if ( (o=fopen(in,"r")) == NULL )
  786. X    return EXIT(con,QUIT);
  787. X  while ( (c=getc(o)) != EOF )
  788. X    FtpWrite(con,c);
  789. X  fclose(o);
  790. X  return FtpClose(con);
  791. X}
  792. END_OF_FILE
  793.   if test 313 -ne `wc -c <'FtpPut.c'`; then
  794.     echo shar: \"'FtpPut.c'\" unpacked with wrong size!
  795.   fi
  796.   # end of 'FtpPut.c'
  797. fi
  798. if test -f 'FtpPwd.c' -a "${1}" != "-c" ; then 
  799.   echo shar: Will not clobber existing file \"'FtpPwd.c'\"
  800. else
  801.   echo shar: Extracting \"'FtpPwd.c'\" \(377 characters\)
  802.   sed "s/^X//" >'FtpPwd.c' <<'END_OF_FILE'
  803. X#include "FtpLibrary.h"
  804. X
  805. Xchar * FtpPwd(FTP * con)
  806. X{
  807. X  String tmp,tmp1;
  808. X  int i;
  809. X  
  810. X  if ( FtpSendMessage(con,"PWD") == QUIT )
  811. X    return (char *) EXIT(con,QUIT);
  812. X  if ( (i=FtpGetMessage(con,tmp)) == QUIT )
  813. X    return (char *) EXIT(con,QUIT);
  814. X  
  815. X  if ( i != 257 )
  816. X    return (char *) EXIT(con,-i);
  817. X
  818. X  sscanf(tmp,"%*[^\"]%*c%[^\"]%*s",tmp1);
  819. X  con -> errno = i;
  820. X  return tmp1;
  821. X}
  822. END_OF_FILE
  823.   if test 377 -ne `wc -c <'FtpPwd.c'`; then
  824.     echo shar: \"'FtpPwd.c'\" unpacked with wrong size!
  825.   fi
  826.   # end of 'FtpPwd.c'
  827. fi
  828. if test -f 'FtpRead.c' -a "${1}" != "-c" ; then 
  829.   echo shar: Will not clobber existing file \"'FtpRead.c'\"
  830. else
  831.   echo shar: Extracting \"'FtpRead.c'\" \(414 characters\)
  832.   sed "s/^X//" >'FtpRead.c' <<'END_OF_FILE'
  833. X#include "FtpLibrary.h"
  834. X
  835. Xint FtpRead(FTP *con)
  836. X{
  837. X  int c;
  838. X  
  839. X  if ( con -> mode == 'I' )
  840. X    return getc(con->data);
  841. X  
  842. X  if ( con->ch != EOF )
  843. X    {
  844. X      c=con->ch;
  845. X      con->ch=EOF;
  846. X      return c;
  847. X    }
  848. X  
  849. X  c=getc(con->data);
  850. X  
  851. X  if ( c == Ctrl('M') )
  852. X    {
  853. X      c = getc ( con->data);
  854. X      
  855. X      if ( c == Ctrl('J') )
  856. X        return '\n';
  857. X      con->ch = c;
  858. X      return Ctrl('M');
  859. X    }
  860. X  return c;
  861. X}
  862. X      
  863. END_OF_FILE
  864.   if test 414 -ne `wc -c <'FtpRead.c'`; then
  865.     echo shar: \"'FtpRead.c'\" unpacked with wrong size!
  866.   fi
  867.   # end of 'FtpRead.c'
  868. fi
  869. if test -f 'FtpRetr.c' -a "${1}" != "-c" ; then 
  870.   echo shar: Will not clobber existing file \"'FtpRetr.c'\"
  871. else
  872.   echo shar: Extracting \"'FtpRetr.c'\" \(375 characters\)
  873.   sed "s/^X//" >'FtpRetr.c' <<'END_OF_FILE'
  874. X#include "FtpLibrary.h"
  875. X
  876. XSTATUS FtpRetr(FTP * con , char * command , char *in , char * out)
  877. X{
  878. X  FILE *o;
  879. X  int c;
  880. X  
  881. X  if ( FtpData(con,command,in,"r") < 1 )
  882. X    return con->errno;
  883. X
  884. X  if ( (o=fopen(out,"w")) == NULL )
  885. X    return EXIT(con,QUIT);
  886. X  while ( (c=FtpRead(con)) != EOF )
  887. X    putc(c,o);
  888. X  if ( c != EOF ) return con -> errno ;
  889. X  fclose(o);
  890. X  return FtpClose(con);
  891. X}
  892. END_OF_FILE
  893.   if test 375 -ne `wc -c <'FtpRetr.c'`; then
  894.     echo shar: \"'FtpRetr.c'\" unpacked with wrong size!
  895.   fi
  896.   # end of 'FtpRetr.c'
  897. fi
  898. if test -f 'FtpSendMessage.c' -a "${1}" != "-c" ; then 
  899.   echo shar: Will not clobber existing file \"'FtpSendMessage.c'\"
  900. else
  901.   echo shar: Extracting \"'FtpSendMessage.c'\" \(303 characters\)
  902.   sed "s/^X//" >'FtpSendMessage.c' <<'END_OF_FILE'
  903. X#include "FtpLibrary.h"
  904. X
  905. XSTATUS FtpSendMessage(FTP *con,char * Message )
  906. X{
  907. X  if ( write ( con -> sock , Message , strlen (Message)) == -1 )
  908. X    return QUIT;
  909. X  if ( write ( con -> sock , "\015\012",2) == -1 )
  910. X    return QUIT;
  911. X  if ( con -> debug != NULL )
  912. X    (*con->debug)(con,0,Message);
  913. X  return 1;
  914. X}
  915. END_OF_FILE
  916.   if test 303 -ne `wc -c <'FtpSendMessage.c'`; then
  917.     echo shar: \"'FtpSendMessage.c'\" unpacked with wrong size!
  918.   fi
  919.   # end of 'FtpSendMessage.c'
  920. fi
  921. if test -f 'FtpWrite.c' -a "${1}" != "-c" ; then 
  922.   echo shar: Will not clobber existing file \"'FtpWrite.c'\"
  923. else
  924.   echo shar: Extracting \"'FtpWrite.c'\" \(279 characters\)
  925.   sed "s/^X//" >'FtpWrite.c' <<'END_OF_FILE'
  926. X#include "FtpLibrary.h"
  927. X
  928. Xint FtpWrite(FTP *con,char c)
  929. X{
  930. X  int i;
  931. X  
  932. X  if ( con -> mode == 'I' )
  933. X    return putc(c,con->data);
  934. X  if ( c == '\n' )
  935. X    {
  936. X      putc(Ctrl('M'),con->data);
  937. X      i=putc(Ctrl('J'),con->data);
  938. X    }
  939. X  else
  940. X    i = putc ( c , con->data );
  941. X  return i;
  942. X}
  943. END_OF_FILE
  944.   if test 279 -ne `wc -c <'FtpWrite.c'`; then
  945.     echo shar: \"'FtpWrite.c'\" unpacked with wrong size!
  946.   fi
  947.   # end of 'FtpWrite.c'
  948. fi
  949. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  950.   echo shar: Will not clobber existing file \"'Makefile'\"
  951. else
  952.   echo shar: Extracting \"'Makefile'\" \(5838 characters\)
  953.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  954. XDEST          = .
  955. X
  956. XEXTHDRS          = /usr/include/arpa/ftp.h \
  957. X        /usr/include/netdb.h \
  958. X        /usr/include/netinet/in.h \
  959. X        /usr/include/stdio.h \
  960. X        /usr/include/sys/socket.h \
  961. X        /usr/include/sys/types.h
  962. X
  963. XHDRS          = FtpLibrary.h
  964. X
  965. XLDFLAGS          =
  966. X
  967. XLIBS          =
  968. X
  969. XLINKER          = gcc
  970. X
  971. XCC            = gcc
  972. X
  973. XSED          = sed
  974. X
  975. XECHO          = echo
  976. X
  977. XCFLAGS        = -I. -O -g
  978. X
  979. XMAKEFILE      = Makefile
  980. X
  981. XOBJS          = FtpBye.o \
  982. X        FtpClose.o \
  983. X        FtpCommand.o \
  984. X        FtpConnect.o \
  985. X        FtpData.o \
  986. X        FtpDebug.o \
  987. X        FtpFull.o \
  988. X        FtpGetMessage.o \
  989. X        FtpGetString.o \
  990. X        FtpGood.o \
  991. X        FtpInitMessage.o \
  992. X        FtpLogin.o \
  993. X        FtpMessage.o \
  994. X        FtpMove.o \
  995. X        FtpNumber.o \
  996. X        FtpOpenDir.o \
  997. X        FtpPort.o \
  998. X        FtpPut.o \
  999. X        FtpPwd.o \
  1000. X        FtpRead.o \
  1001. X        FtpRetr.o \
  1002. X        FtpSendMessage.o \
  1003. X        FtpWrite.o \
  1004. X        test.o
  1005. X
  1006. XPRINT          = pr
  1007. X
  1008. XPROGRAM          = a.out
  1009. X
  1010. XSRCS          = FtpBye.c \
  1011. X        FtpClose.c \
  1012. X        FtpCommand.c \
  1013. X        FtpConnect.c \
  1014. X        FtpData.c \
  1015. X        FtpDebug.c \
  1016. X        FtpFull.c \
  1017. X        FtpGetMessage.c \
  1018. X        FtpGetString.c \
  1019. X        FtpGood.c \
  1020. X        FtpInitMessage.c \
  1021. X        FtpLogin.c \
  1022. X        FtpMessage.c \
  1023. X        FtpMove.c \
  1024. X        FtpNumber.c \
  1025. X        FtpOpenDir.c \
  1026. X        FtpPort.c \
  1027. X        FtpPut.c \
  1028. X        FtpPwd.c \
  1029. X        FtpRead.c \
  1030. X        FtpRetr.c \
  1031. X        FtpSendMessage.c \
  1032. X        FtpWrite.c \
  1033. X        test.c
  1034. X
  1035. Xall:        $(PROGRAM)
  1036. X
  1037. Xlibftp.a:    all
  1038. X        ar cq libftp.a `$(ECHO) $(OBJS)|$(SED) s/test.o//g`
  1039. X        ranlib libftp.a
  1040. X
  1041. X$(PROGRAM):     $(OBJS) $(LIBS)
  1042. X        @echo -n "Loading $(PROGRAM) ... "
  1043. X        @$(LINKER) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROGRAM)
  1044. X        @echo "done"
  1045. X
  1046. Xclean:;        @rm -f $(OBJS)
  1047. X
  1048. Xdepend:;    @mkmf -f $(MAKEFILE) PROGRAM=$(PROGRAM) DEST=$(DEST)
  1049. X
  1050. Xindex:;        @ctags -wx $(HDRS) $(SRCS)
  1051. X
  1052. Xinstall:    $(PROGRAM)
  1053. X        @echo Installing $(PROGRAM) in $(DEST)
  1054. X        @install -s $(PROGRAM) $(DEST)
  1055. X
  1056. Xprint:;        @$(PRINT) $(HDRS) $(SRCS)
  1057. X
  1058. Xprogram:        $(PROGRAM)
  1059. X
  1060. Xtags:           $(HDRS) $(SRCS); ctags $(HDRS) $(SRCS)
  1061. X
  1062. Xupdate:        $(DEST)/$(PROGRAM)
  1063. X
  1064. X
  1065. X
  1066. X###
  1067. XFtpBye.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1068. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1069. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1070. XFtpClose.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1071. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1072. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1073. XFtpCommand.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1074. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1075. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1076. XFtpConnect.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1077. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1078. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1079. XFtpData.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1080. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1081. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1082. XFtpDebug.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1083. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1084. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1085. XFtpFull.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1086. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1087. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1088. XFtpGetMessage.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1089. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1090. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1091. XFtpGetString.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1092. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1093. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1094. XFtpGood.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1095. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1096. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1097. XFtpInitMessage.o: FtpLibrary.h /usr/include/stdio.h \
  1098. X    /usr/include/sys/types.h /usr/include/sys/socket.h \
  1099. X    /usr/include/arpa/ftp.h /usr/include/netinet/in.h \
  1100. X    /usr/include/netdb.h
  1101. XFtpLogin.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1102. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1103. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1104. XFtpMessage.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1105. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1106. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1107. XFtpMove.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1108. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1109. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1110. XFtpNumber.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1111. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1112. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1113. XFtpOpenDir.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1114. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1115. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1116. XFtpPort.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1117. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1118. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1119. XFtpPut.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1120. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1121. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1122. XFtpPwd.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1123. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1124. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1125. XFtpRead.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1126. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1127. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1128. XFtpRetr.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1129. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1130. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1131. XFtpSendMessage.o: FtpLibrary.h /usr/include/stdio.h \
  1132. X    /usr/include/sys/types.h /usr/include/sys/socket.h \
  1133. X    /usr/include/arpa/ftp.h /usr/include/netinet/in.h \
  1134. X    /usr/include/netdb.h
  1135. XFtpWrite.o: FtpLibrary.h /usr/include/stdio.h /usr/include/sys/types.h \
  1136. X    /usr/include/sys/socket.h /usr/include/arpa/ftp.h \
  1137. X    /usr/include/netinet/in.h /usr/include/netdb.h
  1138. END_OF_FILE
  1139.   if test 5838 -ne `wc -c <'Makefile'`; then
  1140.     echo shar: \"'Makefile'\" unpacked with wrong size!
  1141.   fi
  1142.   # end of 'Makefile'
  1143. fi
  1144. if test -f 'fcp.c' -a "${1}" != "-c" ; then 
  1145.   echo shar: Will not clobber existing file \"'fcp.c'\"
  1146. else
  1147.   echo shar: Extracting \"'fcp.c'\" \(453 characters\)
  1148.   sed "s/^X//" >'fcp.c' <<'END_OF_FILE'
  1149. X#include "FtpLibrary.h"
  1150. X
  1151. Xmain(int a,char **b)
  1152. X{
  1153. X  FILE *out,*in;
  1154. X  int c;
  1155. X  
  1156. X
  1157. X  if ( a != 3 )
  1158. X    {
  1159. X      fprintf(stderr,
  1160. X          "Usage: %s node/user/pass:input-file node/user/pass:out-file\n",
  1161. X          b[0]);
  1162. X      exit(1);
  1163. X    }
  1164. X  if ((in=FtpFullOpen(b[1],"r"))==NULL)
  1165. X    perror(b[1]),exit(1);
  1166. X  if ((out=FtpFullOpen(b[2],"w"))==NULL)
  1167. X    perror(b[2]),exit(1);
  1168. X
  1169. X  
  1170. X  while((c=getc(in))!=EOF)
  1171. X    putc(c,out);
  1172. X  FtpFullClose(in);
  1173. X  FtpFullClose(out);
  1174. X}
  1175. END_OF_FILE
  1176.   if test 453 -ne `wc -c <'fcp.c'`; then
  1177.     echo shar: \"'fcp.c'\" unpacked with wrong size!
  1178.   fi
  1179.   # end of 'fcp.c'
  1180. fi
  1181. if test -f 'get.c' -a "${1}" != "-c" ; then 
  1182.   echo shar: Will not clobber existing file \"'get.c'\"
  1183. else
  1184.   echo shar: Extracting \"'get.c'\" \(477 characters\)
  1185.   sed "s/^X//" >'get.c' <<'END_OF_FILE'
  1186. X#include "FtpLibrary.h"
  1187. X
  1188. Xmain(int a,char **b)
  1189. X{
  1190. X  FILE *out,*in;
  1191. X  String localfile;
  1192. X  int c;
  1193. X  
  1194. X
  1195. X  if ( a != 2 )
  1196. X    {
  1197. X      fprintf(stderr,
  1198. X          "Usage: %s node/user/pass:input-file\n",
  1199. X          b[0]);
  1200. X      exit(1);
  1201. X    }
  1202. X  if ((in=FtpFullOpen(b[1],"r"))==NULL)
  1203. X    perror(b[1]),exit(1);
  1204. X  sscanf(b[1],"%*[^:]:%s",localfile);
  1205. X  if ((out=fopen(localfile,"w"))==NULL)
  1206. X    perror(b[2]),exit(1);
  1207. X
  1208. X  while((c=getc(in))!=EOF)
  1209. X    putc(c,out);
  1210. X  FtpFullClose(in);
  1211. X  fclose(out);
  1212. X}
  1213. END_OF_FILE
  1214.   if test 477 -ne `wc -c <'get.c'`; then
  1215.     echo shar: \"'get.c'\" unpacked with wrong size!
  1216.   fi
  1217.   # end of 'get.c'
  1218. fi
  1219. if test -f 'libftp.3' -a "${1}" != "-c" ; then 
  1220.   echo shar: Will not clobber existing file \"'libftp.3'\"
  1221. else
  1222.   echo shar: Extracting \"'libftp.3'\" \(3074 characters\)
  1223.   sed "s/^X//" >'libftp.3' <<'END_OF_FILE'
  1224. X.TH libftp 3
  1225. X.SH NAME
  1226. Xlibftp \- introduce to FTP library.
  1227. X.SH SYNTAX
  1228. X #include <FtpLibrary.h>
  1229. X FtpConnect   (FTP **ftp,char *hostname) 
  1230. X   \- connect to remote host.
  1231. X FtpUser      (FTP *ftp,char *username)
  1232. X   \- send user name to remote daemon.
  1233. X FtpPassword  (FTP *ftp,char *password)
  1234. X   \- send password.
  1235. X FtpAccount   (FTP *ftp,char *account)
  1236. X   \- send account name.
  1237. X FtpLogin     (FTP **ftp,char *user,
  1238. X               char *pass,char *account)
  1239. X FtpLogin     (FTP **ftp,char *user,
  1240. X               char *pass,NULL)
  1241. X   \- full login to remote host.
  1242. X FtpChdir     (FTP *ftp,char *directory)
  1243. X   \- change remote working directory.
  1244. X  
  1245. X FtpMkdir     (FTP *ftp,char *directory)
  1246. X   \- change remote working directory.
  1247. X FtpRm        (FTP *ftp,char *file)
  1248. X   \- erase remote file.
  1249. X FtpType      (FTP *ftp,char type)
  1250. X   \- set file type
  1251. X FtpAscii     (FTP *ftp)
  1252. X   \- set file type to ASCII.
  1253. X FtpBinary    (FTP *ftp)
  1254. X   \- set file type to BINARY.
  1255. X FtpPwd       (FTP *ftp)
  1256. X   \- get working directory.
  1257. X FtpBye       (FTP *ftp)
  1258. X   \- Close ftp connection.
  1259. X FtpCommand   (FTP *ftp,char *command,
  1260. X               param,ans1,ans2,...,EOF)
  1261. X   \- Send command to remote daemon,command for remote daemon
  1262. Xmaking by sscanf(x,command,param).If deamon return answer but not
  1263. Xequivalent answer lists then if set error handler ( by SetErrorHandler ) 
  1264. Xthen call it., else return answer by negative sing.
  1265. X FtpData     (FTP *ftp,char *command,param,mode)
  1266. X Open data connection to remote host.command and param send to remote
  1267. Xdaemon,mode is "r" or "w".Before call it subroutine , you can read/write
  1268. Xby use ftp->data file structure.
  1269. X FtpOpenRead  (FTP *ftp,char *file)
  1270. X   \- Open file for read.
  1271. X FtpOpenWrite (FTP *ftp,char *file)
  1272. X   \- Open file for write.
  1273. X FtpOpenAppend (FTP *ftp,char *file)
  1274. X   \- Open file for append.
  1275. X FtpOpenDir   (FTP *ftp,char *pater)
  1276. X   \- Open directory brief list from remote host.
  1277. X FtpClose     (FTP *ftp)
  1278. X   \- Close file.
  1279. X FtpGetFile   (FTP *ftp,char *file)
  1280. X   \- Send get command to remote daemon.
  1281. X FtpPutFile   (FTP *ftp,char *file)
  1282. X   \- Send put command to remote daemon.
  1283. X FtpRead      (FTP *ftp)
  1284. X   \- Read one character from remote host.
  1285. X FtpWrite     (FTP *ftp,char c)
  1286. X   \- Write one character to remote host.
  1287. X FtpGetString (FTP *ftp,char *s)
  1288. X   \- Get String from data connection.
  1289. X FtpGet       (FTP *ftp,char *remotefile,char *localfile)
  1290. X FtpPut       (FTP *ftp,char *localfile,char *remotefile)
  1291. X FtpDir       (FTP *ftp,char *outfile)
  1292. X FtpDirectory (FTP *ftp,char *pater,char *outfile)
  1293. X   \- Transfer file or lists.
  1294. X FtpFullOpen  (char *filename,char *mode)
  1295. X   \- Open file.return pointer to structure FILE. 
  1296. X    filename: host/user/password:file
  1297. X        mode:     "r","w" or "a".
  1298. X FtpFullClose ( FILE * )
  1299. X   \- Close file opened by FtpFullOpen.
  1300. X FtpSetErrorHanler(FTP *ftp,STATUS (*handler)())
  1301. X FtpSetDebugHanler(FTP *ftp,STATUS (*handler)())
  1302. X   \- Set error and debug handlers.
  1303. X FtpDebug(FTP *ftp)
  1304. X   \- Set standard error and debug handlers.
  1305. X.SH AUTHORS
  1306. X  Oleg Orel 
  1307. X  e-mail: orel@oeaix.oea.ihep.su 
  1308. END_OF_FILE
  1309.   if test 3074 -ne `wc -c <'libftp.3'`; then
  1310.     echo shar: \"'libftp.3'\" unpacked with wrong size!
  1311.   fi
  1312.   # end of 'libftp.3'
  1313. fi
  1314. if test -f 'test.c' -a "${1}" != "-c" ; then 
  1315.   echo shar: Will not clobber existing file \"'test.c'\"
  1316. else
  1317.   echo shar: Extracting \"'test.c'\" \(710 characters\)
  1318.   sed "s/^X//" >'test.c' <<'END_OF_FILE'
  1319. X#include "FtpLibrary.h"
  1320. X
  1321. Xmain(int a,char **b)
  1322. X{
  1323. X  FTP *ftp;
  1324. X  STATUS deb();
  1325. X
  1326. X  if ( b[1]==NULL)
  1327. X    if ( (b[1]=getenv("REMOTE_HOST"))==NULL)
  1328. X      b[1]="localhost";
  1329. X
  1330. X  if (FtpConnect(&ftp,b[1])<1)
  1331. X    {
  1332. X      if ( ftp -> errno == 0 )
  1333. X    perror(b[1]);
  1334. X      else
  1335. X    fprintf(stderr,"EXIT::%s\n",FtpMessage(ftp->errno));
  1336. X      exit(0);
  1337. X    }
  1338. X  FtpSetErrorHandler(ftp,deb);
  1339. X  if ( a < 3 || b[2][0]==0 ) b[2]=getenv("USER");
  1340. X  FtpUser(ftp,b[2]);
  1341. X  if ( a < 4 || b[3][0]==0 ) b[3]=getenv("PASSWORD");
  1342. X  FtpPassword(ftp,b[3]);
  1343. X  if ( a < 5 || b[4][0]==0 )
  1344. X    FtpDir(ftp,"/dev/tty");
  1345. X  else
  1346. X    FtpDirectory(ftp,b[4],"/dev/tty");
  1347. X  FtpBye(ftp);
  1348. X}
  1349. X
  1350. XSTATUS deb(a,b,c)
  1351. X{
  1352. X  fprintf(stderr,"ERROR::%s\n",c);
  1353. X  exit(0);
  1354. X}
  1355. X
  1356. X
  1357. X
  1358. X
  1359. X
  1360. END_OF_FILE
  1361.   if test 710 -ne `wc -c <'test.c'`; then
  1362.     echo shar: \"'test.c'\" unpacked with wrong size!
  1363.   fi
  1364.   # end of 'test.c'
  1365. fi
  1366. echo shar: End of archive 1 \(of 1\).
  1367. cp /dev/null ark1isdone
  1368. MISSING=""
  1369. for I in 1 ; do
  1370.     if test ! -f ark${I}isdone ; then
  1371.     MISSING="${MISSING} ${I}"
  1372.     fi
  1373. done
  1374. if test "${MISSING}" = "" ; then
  1375.     echo You have the archive.
  1376.     rm -f ark[1-9]isdone
  1377. else
  1378.     echo You still must unpack the following archives:
  1379.     echo "        " ${MISSING}
  1380. fi
  1381. exit 0
  1382. exit 0 # Just in case...
  1383.