home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume38 / libftp / part01 / FtpFull.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-13  |  1.6 KB  |  79 lines

  1. #include "FtpLibrary.h"
  2.  
  3. static FTP *ftp_table[256];
  4. static syntax();
  5.  
  6. FILE * FtpFullOpen(char * file , char * mode )
  7. {
  8.   FTP *ftp;
  9.   FILE *tmp;
  10.   String Host,User,Passwd,RemoteFile;
  11.   STATUS i;
  12.  
  13.   if ( ! syntax (file,Host,User,Passwd,RemoteFile))
  14.     {
  15.       tmp=fopen(file,mode);
  16.       ftp_table[fileno(tmp)] = NULL;
  17.       return tmp;
  18.     }
  19.   if ( (i=FtpLogin(&ftp,Host,User,Passwd,NULL)) < 1 )
  20.     return NULL;
  21.  
  22.   FtpBinary(ftp);
  23.  
  24.   switch(mode[0])
  25.     {
  26.     case 'r': 
  27.     if (FtpOpenRead(ftp,RemoteFile)<1) 
  28.       return NULL;
  29.     ftp_table[fileno(ftp->data)] = ftp;
  30.     return ftp->data;
  31.     case 'w':
  32.     if (FtpOpenWrite(ftp,RemoteFile)<1)
  33.       return NULL;
  34.     ftp_table[fileno(ftp->data)] = ftp;
  35.     return ftp->data;
  36.     case 'a':
  37.     if (FtpOpenAppend(ftp,RemoteFile)<1)
  38.       return NULL;
  39.     ftp_table[fileno(ftp->data)] = ftp;
  40.     return ftp->data;
  41.     }
  42. }
  43.  
  44. STATUS   FtpFullClose(FILE *f)
  45. {
  46.   FTP *ftp=ftp_table[fileno(f)];
  47.   if (ftp == NULL)
  48.     return fclose(f);
  49.   FtpClose(ftp);
  50.   return FtpBye(ftp);
  51. }
  52.  
  53. static syntax ( source , host , user , passwd , file)
  54. String source,host,user,passwd,file;
  55. {
  56.   char *in,*out;
  57.   host[0] = user[0] = passwd[0] = file[0] = '\0';
  58.   for ( in = source , out = host;
  59.        *in !='\0' && *in != '/' ;
  60.        *out++ = *in++);
  61.   if ( *in == '\0' ) return 0;
  62.   in++;
  63.   for ( out = user;
  64.        *in !='\0' && *in != '/' ;
  65.        *out++ = *in++);
  66.   if ( *in == '\0' ) return 0;
  67.   in++;
  68.   for ( out = passwd;
  69.        *in !='\0' && *in != ':' ;
  70.        *out++ = *in++);
  71.   if ( *in == '\0' ) return 0;
  72.   in++;
  73.   for ( out = file;
  74.        *in !='\0';
  75.        *out++ = *in++);
  76.   return 1;
  77. }
  78.   
  79.