⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uftpcmd.c

📁 linux下ftp的库源码
💻 C
📖 第 1 页 / 共 3 页
字号:
static char rcsid[] = "$Id: uftpcmd.c,v 5.0 1995/12/10 10:34:21 orel Exp $";/*	$Log: uftpcmd.c,v $ * Revision 5.0  1995/12/10  10:34:21  orel * LIBFTP Version 5.0 (Distributed revision) * * Revision 4.6  1995/12/02  11:24:01  orel * pathes for proxy get thru www-daemon * * Revision 4.5  1995/11/19  09:50:08  orel * Modify flag for reopen * modify reopen itself * for remaking connection when last lost * * Revision 4.4  1995/09/09  09:51:49  orel *  Change type String to FtpString for clean conflicting with *  X11's type string which is pointer to character only. *  Thanks for MIT for this good name of type. * * Revision 4.3  1995/09/09  07:48:33  orel * Some corrections for trafic log file * * Revision 4.2  1995/08/19  18:42:25  orel * *** empty log message *** * * Revision 4.1  1995/07/17  15:27:59  orel * Correct bug in help command * * Revision 4.0  1995/07/11  14:51:08  orel * Libftp version 4.0 * * Revision 3.4  1995/07/04  13:37:12  orel * chenge compctl function * * Revision 3.3  1995/07/02  08:39:06  orel * remove alias for "user" as "login" * * Revision 3.2  1995/06/21  09:28:34  orel * Porting to AIX and some modification.......... * * Revision 3.1  1995/06/20  15:54:28  orel * Porting to AIX * * Revision 3.0  1995/03/20  05:26:29  orel * *** empty log message *** * * Revision 2.17  1995/03/20  05:17:54  orel * *** empty log message *** * * Revision 2.16  1995/03/20  05:17:31  orel * *** empty log message *** * * Revision 2.16  1995/03/20  05:17:31  orel * *** empty log message *** * * Revision 2.15  1995/03/16  09:38:04  orel * modify help * add save(s) funcs * replace readline to getline * etc... * * Revision 2.14  1995/03/07  16:01:40  orel * *** empty log message *** * * Revision 2.13  1995/03/05  15:02:08  orel * *** empty log message *** * * Revision 2.12  1995/02/26  16:41:21  orel * add recursive rm and recursive put * * Revision 2.11  1995/02/26  12:44:02  orel * *** empty log message *** * * Revision 2.10  1995/02/18  15:42:27  orel * add recursive mget * * Revision 2.9  1995/02/17  12:53:18  orel * add parallel put * * Revision 2.8  1995/02/17  12:47:14  orel * add parallel mget * * Revision 2.7  1995/02/13  16:05:10  orel * add setargs call * * Revision 2.7  1995/02/13  16:05:10  orel * add setargs call * * Revision 2.6  1995/02/13  12:08:16  orel * Add save sets * * Revision 2.5  1995/02/08  17:31:53  orel * *** empty log message *** * * Revision 2.4  1995/02/04  09:12:51  orel * rcs id * * Revision 2.4  1995/02/04  09:12:51  orel * rcs id **/#include "uftp.h"jmp_buf connectstack;Ftp_connect_hook(FTP *ftp,int code, char *msg){  FtpLog(ftp->title,msg);  longjmp(connectstack,1);  }  Ftp_connect(ARGS) {  STATUS (*func1)(),(*func2)();  if (*w2==0)    {      w2=getline("Host:");      if (strchr(w2,'\n')!=NULL)	*(char *)strchr(w2,'\n')=0;      else	longjmp(start,1);    }    if (FtpGetHost(w2)==NULL && FtpInit.IO != NULL)     {      char *msg;      extern int h_errno;            switch(h_errno)	{	case HOST_NOT_FOUND:	  msg = "Host unknown";	  break;	case TRY_AGAIN:	          msg = "Hostname lookup failure";break;	default:	          msg = "gethostbyname failure";	  	}      return (*FtpInit.IO)(LINK,QUIT,msg);    }    newframe(0);    func1 = FtpInit.error;  func2 = FtpInit.IO;    if (trymode)     {      FtpSetErrorHandler(&FtpInit,Ftp_connect_hook);      FtpSetIOHandler(&FtpInit,Ftp_connect_hook);      setjmp(connectstack);    }  list_add(&hosts,w2);    FtpConnect(&LINK,w2);  strcpy(iftp[frame].host,FtpGetHost(w2)->h_name);    FtpSetErrorHandler(LINK,func1);  FtpSetErrorHandler(&FtpInit,func1);  FtpSetIOHandler(LINK,func2);  FtpSetIOHandler(&FtpInit,func2);    return;}Ftp_preconnect(ARGS){  FtpString host;  FtpString pass;    gethostname(host, sizeof host);  strcpy(host,FtpGetHost(host)->h_name);  sprintf(pass,"%s@%s",getpwuid(getuid())->pw_name,host);    newframe(0);  if (*w2==0)   {     w2=getline("Host:");     if (strchr(w2,'\n')!=NULL)       *(char *)strchr(w2,'\n')=0;     else       longjmp(start,1);   }  strcpy(iftp[frame].host,w2);    if (*w3==0)    w3=defaultuser;  strcpy(iftp[frame].user,w3);  if (*w4==0)    w4=pass;  strcpy(iftp[frame].pass,w4);  if (*w5==0)    w5=".";  strcpy(iftp[frame].pwd,w5);    iftp[frame].lock=0;  ftp[frame]=FtpCreateObject();}Ftp_user(ARGS){  FtpString tmp;    if (*w2==0)    {      sprintf(tmp,"login (default %s):",defaultuser);      w2=getline(tmp);      if (strchr(w2,'\n')!=NULL)	*(char *)strchr(w2,'\n')=0;      else	longjmp(start,1);      if (*w2==0) 	w2=defaultuser;    }  strcpy(iftp[frame].user,w2);  strcpy(iftp[frame].pass,w3);  if (FtpUser(LINK,w2)==331) Ftp_pass("",w3,"","","","");}Ftp_pass(ARGS){  FtpString tmp;  if (*w2==0)     {      FtpString pass;      FtpString host;        gethostname(host, sizeof host);      strcpy(host,FtpGetHost(host)->h_name);      sprintf(pass,"%s@%s",getpwuid(getuid())->pw_name,host);      sprintf(tmp,"Password (default %s):",pass);      w2=(char*)getpass(tmp);      if (*w2==0) w2=pass;    }    strcpy(iftp[frame].pass,w2);  FtpPassword(LINK,w2);  strcpy(iftp[frame].pwd,FtpPwd(LINK));}Ftp_HTTP_open(ARGS){  int c;  FtpString protocol,host,path,file;  FTP_STAT *stat=NULL;  char *p;    /* ftp://hostname.domain/path/file */  if ( (c=sscanf ( w2, "%[^:]://%[^/]/%s", protocol, host, path )) <2 )    return 0;  if (strcasecmp(protocol,"ftp")!=0) return 0;  if (c==2) strcpy(path,"/");  if ((p=strrchr(path,'/'))!=NULL)    {      strcpy(file,p+1);      *(p-1)=0;    }  else    {      strcpy(file,path);      strcpy(path,"/");    }  if (!*path) strcpy(path,"/");    Ftp_ftp("ftp",host,path,"","","");  FtpStat(LINK,file,&stat);  if (stat==NULL) return 1;    if (stat->type=='d') Ftp_cd(LINK,file,"","","","");  if (stat->type=='-')    {      Ftp_get("get",file,"","","","");      if (!interactive) Ftp_quit("","","","","","");    }  return 1;}  Ftp_open(ARGS){  STATUS (*err)();  /* There two possibilities to describe future connection:     1st: host user passwd dir     1nd: HTML-spec  */  if (Ftp_HTTP_open(w1,w2,"","","",""))    return;    Ftp_connect("",w2,"","","","");  Ftp_user("",w3,w4,"","","" );  if (ifalias("autologin")) execute("autologin");  if (*w5)     Ftp_cd("cd",w5,"","","","");}Ftp_reopen(ARGS){  FtpString host,user,pass,pwd;  strcpy(host,iftp[frame].host);  strcpy(user,iftp[frame].user);  strcpy(pass,iftp[frame].pass);  strcpy(pwd,iftp[frame].pwd);  if ( host[0]!=0 )    {      Ftp_close(NULLARGS);      Ftp_open("",host,user,pass,pwd,"");    }  else    {      log("Need at least hostname");    }}Ftp_ftp(ARGS){  FtpString pass;  FtpString host;    /* There two possibilities to describe future connection:     1st: host dir     1nd: HTML-spec  */  if (Ftp_HTTP_open(w1,w2,"","","",""))    return;  gethostname(host, sizeof host);  strcpy(host,FtpGetHost(host)->h_name);  sprintf(pass,"%s@%s",getpwuid(getuid())->pw_name,host);    Ftp_open("",w2,"anonymous",pass,w3,"");  return;}Ftp_quit(ARGS){  quit(0);}Ftp_mput_handler(){  log("File(s) or directory not found");  longjmp(start,1);}Ftp_lcd(ARGS){  glob_t gl;  FtpString tmp;    bzero(&gl,sizeof gl);   glob(w2,GLOB_BRACE|GLOB_TILDE|GLOB_QUOTE,       Ftp_mput_handler, &gl);      if (gl.gl_matchc<1 || chdir(*gl.gl_pathv))    perror(w2);    fprintf(stderr,"Local directory is \"%s\"\n",getwd(tmp));}Ftp_close(ARGS){  register int i;    if (isdigit(*w2))     {      i=atoi(w2);    }  else     {      i=frame;    }    FtpQuickBye(ftp[i]);    iftp[i].host[0]=0;  iftp[i].pwd[0]=0;  ftp[i]=NULL;  newframe(1);}INLINE SetLogicalVar(char arg, int * var, char *msg){  switch(arg)    {          case 'y':            *var=1;      break;          case 'n':            *var=0;      break;          default:            (*var)?(*var=0):(*var=1);      break;    }}Ftp_set(ARGS){  if (!strcmp("frame",w2))    return atoi(w3)<NFRAMES?frame=atoi(w3):0;    if (!strcmp("timeout",w2))    {      FtpSetTimeout(&FtpInit,atoi(w3));      if (LINK!=0)	FtpSetTimeout(LINK,atoi(w3));      return;    }    if (!strcmp("sleep",w2))    {      sleeptime=atoi(w3);      return;    }    if (!strcmp("debug",w2))    {      if ( *w3=='y' || *w3==0) 	{ 	  if (LINK!=NULL) FtpSetDebugHandler(LINK,FtpDebugDebug);	  FtpSetDebugHandler(&FtpInit,FtpDebugDebug);	  return;	}      if ( *w3 == 'n')	{	  if (LINK!=NULL) FtpSetDebugHandler(LINK,NULL);	  FtpSetDebugHandler(&FtpInit,NULL);	  return;	}    }    if (!strcmp("bin",w2))    {      if ( *w3=='y' || *w3==0) 	{ 	  FtpInit.mode='I';	  return;	}      if ( *w3 == 'n')	{	  FtpInit.mode='A';	  return;	}    }    if (!strcmp("try",w2))    return SetLogicalVar(*w3,&trymode,"Try mode");  if (!strcmp("hash",w2))    return SetLogicalVar(*w3,&hashmode,"Hash mode");  if (!strcmp("rest",w2)||!strcmp(w2,"restore"))    return SetLogicalVar(*w3,&restmode,"Restore mode");    if (!strcmp("prompt",w2))    {      strcpy(prompt,w3);      return;    }    if (!strcmp("port",w2))    {      if ( isdigit(*w3)) 	return FtpSetPort(&FtpInit,atoi(w3));      return;    }  if (!strcmp("wwwport",w2))    {      if ( isdigit(*w3)) 	return www_port=atoi(w3);      return;    }  if (!strcmp("wwwgateway",w2))    {      strcpy(www_gateway,w3);      return;    }  if (!strcmp("noopinterval",w2)||!strcmp("noop",w2))    {      if ( isdigit(*w3)) 	return noopinterval=(time_t)atoi(w3);      fputs("Time must be number\n",stderr);      return;    }  if (!strcmp("nooptimeout",w2))    {      if ( isdigit(*w3)) 	return nooptimeout=(time_t)atoi(w3);      fputs("Time must be number\n",stderr);      return;    }        if (!strcmp("user",w2))    {      strcpy(defaultuser,w3);      return;    }    if (!strcmp("",w2))    {      fprintf(stderr,"frime %d\n",frame);      fprintf(stderr,"timeout %d secs\n",FtpInit.timeout.tv_sec);

⌨️ 快捷键说明

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