ftpio.c

来自「linux下ftp的库源码」· C语言 代码 · 共 218 行

C
218
字号
static char rcsid[] = "$Id: FtpIO.c,v 5.0 1995/12/10 10:28:38 orel Exp $";/*	$Log: FtpIO.c,v $ * Revision 5.0  1995/12/10  10:28:38  orel * LIBFTP Version 5.0 (Distributed revision) * * Revision 4.1  1995/12/02  11:23:07  orel * *** empty log message *** * * Revision 4.0  1995/07/11  07:00:26  orel * Libftp Version 4.0 * * Revision 4.0  1995/07/11  07:00:26  orel * Libftp Version 4.0 * * Revision 3.0  1995/03/20  05:26:07  orel * *** empty log message *** * * Revision 3.0  1995/03/20  05:26:07  orel * *** empty log message *** * * Revision 2.6  1995/03/20  05:18:13  orel * *** empty log message *** * * Revision 2.5  1995/02/26  16:46:50  orel * *** empty log message *** * * Revision 2.5  1995/02/26  16:46:50  orel * *** empty log message *** * * Revision 2.4  1995/02/18  15:42:53  orel * modify for recurive mget * * Revision 2.4  1995/02/18  15:42:53  orel * modify for recurive mget * * Revision 2.3  1995/02/04  09:02:53  orel * add rcsid * * Revision 2.3  1995/02/04  09:02:53  orel * add rcsid **//*		      Library for ftpd clients.(libftp)			Copyright by Oleg Orel			 All rights reserved.			This  library is desined  for  free,  non-commercial  software  creation. It is changeable and can be improved. The author would greatly appreciate any  advises, new  components  and  patches  of  the  existing  programs.Commercial  usage is  also  possible  with  participation of it's author.*/#include "FtpLibrary.h"int FtpRead(FTP *con){  int c;    if ( con -> mode == 'I' )    return FtpGetc(con,FTPDATA(con));    if ( con->ch != EOF )    {      c=con->ch;      con->ch=EOF;      return c;    }    c=FtpGetc(con,FTPDATA(con));    if ( c == Ctrl('M') )    {      c = FtpGetc(con,FTPDATA(con));            if ( c == Ctrl('J') )	return '\n';      con->ch = c;      return Ctrl('M');    }  return c;}int FtpWrite(FTP *ftp,char c){    if ( ftp -> mode == 'I' || c != '\n' )    return FtpPutc(ftp,FTPDATA(ftp),c);    FtpPutc(ftp,FTPDATA(ftp),Ctrl('M'));  return FtpPutc(ftp,FTPDATA(ftp),Ctrl('J'));}	  int FtpGetc(FTP *ftp,FILE *fp){  fd_set fds;  char c;    FD_ZERO(&fds);  FD_SET(fileno(fp),&fds);  if (select(getdtablesize(), &fds, 0, 0, &(ftp->timeout))<1)    return EXIT(ftp,QUIT);  if (read(fileno(fp),&c,1)<1)    return EOF;    if (ftp->hash!=NULL) (*ftp->hash)(ftp,1);    return (int)c;}STATUS FtpPutc(FTP *ftp,FILE *fp,char c){  fd_set fds;    FD_ZERO(&fds);  FD_SET(fileno(fp),&fds);    if (select(getdtablesize(), 0, &fds, 0, &(ftp->timeout))<1)    return EXIT(ftp,QUIT);    if (write(fileno(fp),&c,1)!=1)    return EXIT(ftp,QUIT);  if (ftp->hash!=NULL) (*ftp->hash)(ftp,1);}STATUS FtpReadBlock(FTP *ftp, char *buffer, int size){  fd_set fds;  register int rsize,status;    FD_ZERO(&fds);  FD_SET(fileno(FTPDATA(ftp)),&fds);    if (select(getdtablesize(), &fds,0, 0, &(ftp->timeout))<1)    return EXIT(ftp,QUIT);      if ((rsize=read(fileno(FTPDATA(ftp)),buffer,size))<0)    return EXIT(ftp,QUIT);    if (ftp->hash!=NULL && rsize!=0) (*ftp->hash)(ftp,rsize);    if (ftp->mode == 'A')    {      char buffer2[size];      register int i,ii;      for (i=0,ii=0;i<rsize;i++,ii++)	if (buffer[i]==Ctrl('M')&&buffer[i+1]==Ctrl('J'))	  buffer2[ii]='\n',i++;	else	  buffer2[ii]=buffer[i];            rsize=ii;      bcopy(buffer2,buffer,rsize);    }  return rsize;}STATUS FtpWriteBlock(FTP *ftp, char *buffer, int size){  fd_set fds;  register int wsize;  char buffer2[size*2];    FD_ZERO(&fds);  FD_SET(fileno(FTPDATA(ftp)),&fds);    if (select(getdtablesize(), 0, &fds, 0, &(ftp->timeout))<1)    return EXIT(ftp,QUIT);      if (ftp->mode=='A')    {      register int i,ii;      for(i=0,ii=0;i<size;i++,ii++)	if (buffer[i]=='\n')	  buffer2[ii++]=Ctrl('M'),buffer2[ii]=Ctrl('J');	else	  buffer2[ii]=buffer[i];      buffer=buffer2;      size=ii;    }    if ((wsize=write(fileno(FTPDATA(ftp)),buffer,size))!=size)     return EXIT(ftp,QUIT);    if ( ftp->hash!=NULL && wsize!=0 ) (*ftp->hash)(ftp,wsize);    return wsize;}    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?