📄 uftp.c
字号:
default: ADD(p1,'$');ADD(p1,*p);continue; } } if (!dollar) { ADD(p1,' '); ADDSTR(&p1,args); } *p=0; return new;}ifalias(char *cmd){ if (*getalias(cmd)!=0) return 1; return 0;}char *getalias(char *cmd){ FtpString what; ALIAS *a=firstalias; strcpy(what,word(cmd,1)); while ( a!=NULL) { if (!strcmp(a->name,what)) return a->str; a=a->next; } return "";}ifcmd(char *arg){ CMDS *_cmds = &cmds[0]; FtpString cmd; strcpy(cmd,word(arg,1)); while (1) { if (_cmds->cmd==NULL) return 0; if (!strcmp(cmd,_cmds->cmd)) return 1; _cmds++; }}char *getprompt(){ static FtpString _prompt; FtpString tmp; char *s; _prompt[0]=0; for(s=prompt;*s;s++) switch (*s) { case '%': switch (*++s) { case 'H': strcat(_prompt,iftp[frame].host); break; case 'h': strcpy(tmp,iftp[frame].host); if (strchr(tmp,'.')!=NULL) *(char *)strchr(tmp,'.')=0; strcat(_prompt,tmp); break; case 'M': gethostname(tmp, sizeof tmp); strcat(_prompt,gethostbyname(tmp)->h_name); break; case 'm': gethostname(tmp, sizeof tmp); strcpy(tmp,gethostbyname(tmp)->h_name); if (strchr(tmp,'.')!=NULL) *(char *)strchr(tmp,'.')=0; strcat(_prompt,tmp); break; case 'u': strcat(_prompt,iftp[frame].user); break; case 'd': strcat(_prompt,iftp[frame].pwd); break; case 'D': strcat(_prompt,(char *)getcwd(tmp,sizeof(tmp))); break; case 'f': sprintf(tmp,"%d",frame); strcat(_prompt,tmp); break; case 'p': sprintf(tmp,"%d",(LINK==NULL)?0:LINK->port); strcat(_prompt,tmp); break; case 't': sprintf(tmp,"%d",(LINK==NULL)?0:LINK->timeout.tv_sec); strcat(_prompt,tmp); break; case 'T': { time_t t=time((time_t *)0); struct tm *lt=localtime(&t); sprintf(tmp,"%02d:%02d:%02d",lt->tm_hour, lt->tm_min,lt->tm_sec); strcat(_prompt,tmp); } break; case 'P': sprintf(tmp,"%d",getpid()); strcat(_prompt,tmp); break; default: sprintf(tmp,"%%%c",*s); strcat(_prompt,tmp); break; } break; case '^': ++s; if (isalpha(*s)) { sprintf(tmp,"%c",toupper(*s)-'A'+1); strcat(_prompt,tmp); } break; default: sprintf(tmp,"%c",*s); strcat(_prompt,tmp); break; } return _prompt;} void noop(){ int i; time_t curtime,save; STATUS (*func1)(),(*func2)(),(*func3)(); if (noopinterval==0) return; curtime = time((time_t *)0); signal(SIGALRM,noop); if (prevtime==0) { prevtime=curtime; alarm(noopinterval); return; } if (curtime-prevtime < noopinterval) { alarm(prevtime+noopinterval-curtime); return; } fprintf(stderr,"Waiting...");fflush(stderr); for (i=0;i<NFRAMES;i++) { if ( ftp[i]==NULL || FTPCMD(ftp[i]) == NULL || iftp[i].lock ) continue; func1=ftp[i]->debug; ftp[i]->debug=NULL; func2=ftp[i]->error; ftp[i]->error=NULL; func3=ftp[i]->IO; ftp[i]->IO=NULL; save = ftp[i]->timeout.tv_sec; ftp[i]->timeout.tv_sec = nooptimeout; FtpCommand(ftp[i],"NOOP","",0,EOF); ftp[i]->timeout.tv_sec = save; ftp[i]->debug=func1; ftp[i]->error=func2; ftp[i]->IO=func3; } alarm(noopinterval); prevtime=curtime; for (i=0;i<10;i++) putc(8,stderr),putc(' ',stderr),putc(8,stderr); fflush(stderr);}setsignals(){ signal(SIGINT,intr); signal(SIGQUIT,intr);#ifdef SIGURG signal(SIGURG,SIG_IGN);#endif signal(SIGIO,SIG_IGN); signal(SIGCHLD,SIG_IGN); signal(SIGPIPE,SIG_IGN);#if defined(TIOCGWINSZ) && defined(SIGWINCH) signal(SIGWINCH,getwinsz);#endif noop();}unsetsignals(){ signal(SIGALRM,SIG_IGN); alarm(0);}int myhash(FTP *ftp,unsigned int chars){ if (chars==0) return ftp -> counter=0; ftp -> counter += chars; if (hashmode) { fprintf(stderr,"%10u bytes transfered\r",ftp -> counter); fflush(stderr); } if (!lastcmd) { noop(); alarm(0); }}char *makefilename(char *f1, char *f2){ char *p; if (*f2!=0) return f2; if ( (p=strrchr(f1,'/'))!=NULL) return p+1; return f1;}redir(char *cmdline){ char *p=cmdline; FtpString result; char *r=result; for ( ; *p ; p++ , r++ ) { if ( *p == '\\' ) { *r = * ++ p ; continue; } if ( *p == '>' || *p == '<' ) { FtpString filename; char *q=filename; char c = *p; for (p++;isspace(*p)&&*p!=0;p++); if (*p=='"') { for (p++; *p!='"' && *p!=0 ; p++,q++) *q = *p; if (*p!='"') p++; } else for (; !isspace(*p) && *p!=0 ; p++,q++) *q = *p; *q=0; if ( c == '>' ) output(filename); else input(filename); } *r = *p; } *r=0; strcpy(cmdline,result);}int itty = -1,otty = -1;FILE *is=NULL, *os=NULL;input(char *filename){ if ((is=Ftpfopen(filename,"r"))==NULL) { perror(filename); return; } fflush(stdin); itty=dup(0); close(0); dup2(fileno(is),0);}output(char *filename){ if ((os=Ftpfopen(filename,"w"))==NULL) { perror(filename); return; } fflush(stdout); otty=dup(1); close(1); dup2(fileno(os),1);}redirback(){ if (itty!= -1) { fflush(stdin); close(0); Ftpfclose(is); dup2(itty,0); is=NULL; itty = -1; } if (otty!= -1) { fflush(stdout); close(1); Ftpfclose(os); dup2(otty,1); os=NULL; otty = -1; }}batch(char *filename){ FILE *fp; FtpString tmp; if ((fp=fopen(filename,"r"))!=NULL) { while ( fgets(tmp, sizeof tmp, fp) != NULL) { tmp[strlen(tmp)-1]=0; execute(tmp); if (tmp[0]) gl_histadd(tmp); } fclose(fp); }} quit(int code){ if (ifalias("autoquit")) execute("autoquit"); exit(code);}#if defined(TIOCGWINSZ) && defined(SIGWINCH)void getwinsz(){ struct winsize win; ioctl(0,TIOCGWINSZ,&win); winsize = win.ws_col; if (winsize==0) winsize=80; gl_setwidth(winsize); gl_redraw_r();}#endifload_compctl(){ /* Load command(s) */ static char *sets[] = { "frame","timeout","sleep","debug","bin","try","hash", "port","prompt","rest","noopinterval","nooptimeout","user", "wwwgateway","wwwport", NULL}; char **p; CMDS *xcmd = &cmds[0]; ALIAS *a=firstalias; while (xcmd->cmd != NULL) load_key(xcmd->cmd),xcmd++; /* Load alias(es) */ while (a!=NULL) load_key(a->name),a=a->next; for (p=sets;*p!=NULL;p++) { FtpString tmp; strcpy(tmp,"set "); strcat(tmp,*p); load_key(tmp); } load_hosts(); }load_hosts(){ FILE *in=fopen(gethostsname(),"r"); FtpString s,ss; if (in==NULL) return; while ( fgets(s,sizeof s,in)!=NULL) { s[strlen(s)-1]=0; strcpy(ss,"open "); strcat(ss,s); load_key(ss); } fclose(in);}log_traffic ( char *hf, char *ht, char *ff, char *ft, int counter){ time_t t=time((time_t *)0); struct tm *lt=localtime(&t); FtpString hostname,txt; int fd=open(LOG_TRAFFIC_FILE,O_WRONLY|O_CREAT|O_APPEND); if (fd==-1) return; while ((status=flock(fd,LOCK_EX)==-1) && errno==EWOULDBLOCK); if (status==-1) return; gethostname(hostname, sizeof hostname); sprintf(txt,"%02d:%02d:%02d %02d:%02d:%02d %s@%s %s:%s -> %s:%s %d bytes\n", lt->tm_mday,lt->tm_mon+1,lt->tm_year+1900, lt->tm_hour,lt->tm_min,lt->tm_sec, getpwuid(getuid())->pw_name,hostname, hf, ff, ht, ft, counter) ; write(fd,txt,strlen(txt)); close(fd);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -