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

📄 uftpcmd.c

📁 linux下ftp的库源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	  memset(a,0,sizeof(ALIAS));	  a -> next = NULL;	  break;	}            if (!strcmp(a->name,w2))	break;            if ( a->next == NULL)	{	  a -> next = (ALIAS *) malloc(sizeof(ALIAS));	  a = a->next;	  memset(a,0,sizeof(ALIAS));	  a -> next = NULL;	  break;	}      a=a->next;    }  strcpy(a -> name,w2);  strcpy(a -> str,makestr(w3,w4,w5,w6,NULL));}Ftp_mkalias(ARGS){  FtpString new;  if (!*w2) return puts("Arg must present\n");  sprintf(new,"open \"%s\" \"%s\" \"%s\" \"%s\"",	  iftp[frame].host,iftp[frame].user,	  iftp[frame].pass,iftp[frame].pwd);    Ftp_alias("alias",w2,new,"","","");}Ftp_unalias(ARGS){  ALIAS *cur,*prev;  cur=prev=firstalias;  while ( cur != NULL )    {      if (!strcmp(cur->name,w2))	{	  if ( cur == firstalias )	    {	      firstalias = cur->next;	      free(cur);	      return;	    }	  prev -> next = cur -> next;	  free(cur);	}      prev=cur;      cur=cur->next;    }}Ftp_save_aliases(ARGS){  ALIAS *a=firstalias;  FILE *out;    if ((out=fopen (getaliasrcname(),"w"))==NULL)    {      perror(getaliasrcname());      return;    }  while (a!=NULL)    {      fprintf(out,"alias %s '%s'\n",a->name,a->str);      a=a->next;    }  fclose(out);    chmod ( getaliasrcname(), 0600);}Ftp_save_sets(ARGS){  FILE *out;  FtpString newprompt;  char *p1=prompt, *p2=newprompt;    if ((out=fopen (getsetsrcname(),"w"))==NULL)    {      perror(getaliasrcname());      return;    }  fprintf(out,"set timeout %d\n",FtpInit.timeout.tv_sec);  fprintf(out,"set sleep %d\n",sleeptime);  fprintf(out,"set debug %c\n",(FtpInit.debug!=NULL)?'y':'n');  fprintf(out,"set try %c\n",trymode?'y':'n');  fprintf(out,"set hash %c\n",hashmode?'y':'n');  fprintf(out,"set rest %c\n",restmode?'y':'n');  fprintf(out,"set bin %c\n", (FtpInit.mode=='I')?'y':'n');  while (*p1)    {      if (*p1=='>'||*p1=='<') *p2++='\\';      *p2++ = *p1++;    }  *p2=0;    fprintf(out,"set prompt '%s'\n",newprompt);    fprintf(out,"set port %d\n",FtpInit.port);  fprintf(out,"set noopinterval %d\n",noopinterval);  fprintf(out,"set nooptimeout %d\n",nooptimeout);  fprintf(out,"set user '%s'\n",defaultuser);    fclose(out);    chmod ( getsetsrcname(), 0600);  }#define ARCHIE_MAX_TARGETS 20Ftp_acd(ARGS){  static int targets=0;  static FtpString what={0};  static ARCHIE result[ARCHIE_MAX_TARGETS];  FtpString tmp;    int i, selected_target;  char *p;    if ( (what[0] == 0 || strcmp(w2,what) != 0) && *w2!=0 )    {      if ((targets=FtpArchie(w2,result,ARCHIE_MAX_TARGETS))<1) 	return puts("Archie failure or target not found");      strcpy(what,w2);    }    for (i=0;i<targets;i++)    fprintf(stderr,"%2d %s:%s\n",i,result[i].host,result[i].file);    if (strcmp(w1,"archie")==0)    return;      p = getline("Your selection? ");  if (strchr(p,'\n')!=NULL)    *(char *)strchr(p,'\n')=0;  else    longjmp(start,1);    if (*word(p,1)==0) return;    selected_target = atoi(p);  if (strcmp(w1,"acd")==0 || *(strrchr(result[selected_target].file,'/')+1)=='\0' )    {      strcpy(tmp,result[selected_target].file);      *(char*)strrchr(tmp,'/')=0;            Ftp_ftp("ftp",result[selected_target].host,tmp,"","","");    }  else    {      Ftp_ftp("ftp",result[selected_target].host,"","","","");      Ftp_get("get",result[selected_target].file,"","","","");    }  }Ftp_aaget(ARGS){  ARCHIE result[ARCHIE_MAX_TARGETS];  int targets;  int maxsize;  register int i;  FtpString pass,host,tmp;  FTP save;    if (*w2==0)    {      printf("%s <filename>\n",w1);      return;    }    if ((targets=FtpArchie(w2,result,ARCHIE_MAX_TARGETS))<1)     {      printf("Specified file not found by archie\n");      return;    }  gethostname(host, sizeof host);  sprintf(pass,"%s@%s",getpwuid(getuid())->pw_name,FtpGetHost(host)->h_name);    for (i=0,maxsize=0;i<targets;i++)    if (result[i].size>maxsize) maxsize=result[i].size;    for (i=0; ; i++,(i==targets)?i=0:i)    {      FTP *ftp;            if (result[i].size<maxsize) continue;      save=FtpInit;      FtpSetIOHandler(&FtpInit,NULL);      FtpSetErrorHandler(&FtpInit,NULL);            sprintf(tmp,"Retrive file %s from %s.....",result[i].file,result[i].host);      FtpLog("aaget",tmp);            if (FtpError(FtpLogin(&ftp,result[i].host,"anonymous",pass,NULL)) ||	  FtpError(FtpGet(ftp,result[i].file,strrchr(result[i].file,'/')+1)))	{	  FtpQuickBye(ftp);	  continue;	}      FtpQuickBye(ftp);      break;    }  FtpInit=save;  }INLINE char filetype(char *name){  struct stat st;  if (stat(name,&st)==-1) return '0';    if ( S_IFREG == (st.st_mode & S_IFMT)) return '-';  if ( S_IFDIR == (st.st_mode & S_IFMT)) return 'd';    return '?';}Ftp_mput(ARGS){  glob_t gl;  char **args;  int nargs;  int chmod_status=0;  FtpString local,pwd;  FtpString tmp;    glob((*w2==0)?"*":w2,GLOB_BRACE|GLOB_TILDE|GLOB_QUOTE,       Ftp_mput_handler, &gl);  nargs=gl.gl_matchc;  args=gl.gl_pathv;    while(nargs--)    {      if (filetype(*args)=='-')	{	  struct stat st;	  getcwd(local,sizeof local);	  	  sprintf(tmp,"put %s/%s",local,*args);	  log(tmp);	  	  Ftp_get("put",*args,"","","","");	  stat(*args,&st);	  if (chmod_status>=0)	    chmod_status=FtpStatus(LINK,FtpChmod(LINK,*args,st.st_mode&0777));	}      args++;    }  nargs=gl.gl_matchc;  args=gl.gl_pathv;    while(nargs--)    {      if (filetype(*args)=='d')	{	  getcwd(local,sizeof local);	  if (chdir(*args)==-1) continue;	  strcpy(pwd,iftp[frame].pwd);	  FtpStatus(LINK,FtpMkdir(LINK,*args));	  	  if (!FtpError(FtpStatus(LINK,FtpChdir(LINK,*args))))	    {	      Ftp_mput(NULLARGS);	      FtpChdir(LINK,pwd);	    }	  chdir(local);	}      args++;    }}Ftp_env(ARGS){  if (!strcmp(w1,"setenv")) return setenv(w2,w3);  if (!strcmp(w1,"unsetenv")) return unsetenv(w2);  if (!strcmp(w1,"env")) return printenv();}Ftp_compctl(ARGS){  if (*w2==0) return print_ctl("compctl",NULL);  load_key(makestr(w2,w3,w4,w5,w6,NULL));}CMDS cmds[]={    "compctl",		Ftp_compctl,      0,  "compctl command arg1 arg2... - load complition map",  "connect",		Ftp_connect,      0,  "connect <hostname> - make new ftp connection",  "preconnect",		Ftp_preconnect,      0,  "preconnect <hostname> <user> <password> <path> - make fictivity  ftp connection",  "open",		Ftp_open,         0,  "open <hostname> <user> <pass> <directory> - login to server",    "reopen",		Ftp_reopen,       0,  "reopen - Open again connection with existing frame information",    "ftp",		Ftp_ftp,          0,  "ftp <hostname> - anonymously login to server",    "close",		Ftp_close,        1,  "close - Close connection",    "quit",		Ftp_quit,         0,  "quit - Exit from uftp",    "exit",		Ftp_quit,         0,  "exit - Exit from uftp",    "set",		Ftp_set,          0,"set - Set variables: (Without args print current settings)\n\       frame <number>    - select another session(frame)\n\       timeout <secs>    - Set network timeout\n\       nooptimeout <secs>- Set network timeout with clearing timeout\n\       noop <secs>       - Set time interval for sending NOOP operator\n\                           to server for erased delay\n\       sleep <secs>      - Set pause beetween transfer attempt\n\       debug <y|n>       - Set debuging ftp's protocol (Default no)\n\       try <y|n>         - Set retransfer mode with broken network (Default yes)\n\       hash <y|n>        - Set hashing transfer (Default no)\n\       restore <y|n>     - Set retransfer mode (reget/reput) (Default yes!!!!)\n\       bin <y|n>         - Set automatic turn on binary mode (Default no) \n\       prompt <string>   - Set prompt (See help prompt)\n\       port <number>     - Set ftpd's port for next sessions\n\       user <name>       - Set default user name (default you name)",  "setenv",            Ftp_env,           0,  "setenv - Set enviroment variable",	   "unsetenv",          Ftp_env,           0,  "unsetenv - Unset enviroment variable",	   "env",               Ftp_env,           0,  "env - Print enviroment variables",	 	   "prompt",               NULL,         0,  "\prompt is a string, which may be contains %<char> or ^<char> combitanion, which have next interprets:%H, %h - full and short remote host names%M, %m - full and short local host names%u     - remote user's name%d     - remote current directory%D     - local current directory%f     - number of current frame%p     - the ftp's port number%t     - timeout %T     - current time %P     - uftp process id%%     - character %^<char>- control character%^     - character ^",  "list",		Ftp_list,         0,"list - List session's information",  "user",		Ftp_user,         1,"user <user> - send user's name",  "pass",		Ftp_pass,         1,"pass <pass> - send user's password",  "bin",		Ftp_bin,          1,"bin - Set binary mode for current frame",  "ascii",		Ftp_ascii,        1,"ascii - Set ASCII mode for current frame",  "cd",			Ftp_cd,           1,"cd <directory> - change current remote directory ",  "acd",		Ftp_acd,          0,"acd <file_or_directory> - search pointed directory using archie, and setup connection to it",  "lcd",		Ftp_lcd,          0,"lcd <directory> - Change local directory",  "abort",		Ftp_abort,        1,"abort - abort last operation",  "mkdir",		Ftp_mkdir,        1,"mkdir <dirname> - create new directory",  "rm",		        Ftp_rm,           1,"rm <filename_spec> - remove file(s)",  "mv",		        Ftp_move,         1,"mv <old> <new> - rename file",  "dir",		Ftp_get,          1,"dir <argslist> ... - print list of files",  "ls",		        Ftp_get,          1,"ls <arglist> ... - print short list of files",  "get",		Ftp_get,          1,"get <remote_file> [<local_file>] - receive file from server",  "pget",		Ftp_proxyget,          0,"pget <http_spec> [<local_file>] - receive file from server thru HTTP proxy server",  "mget",		Ftp_mget,         1,"mget <remote_file(s)> - recursive receive file(s) from server",  "aget",		Ftp_acd,          0,"aget <file> - search pointed file using archie, and retrive it",  "aaget",		Ftp_aaget,        0,"aaget <file> - search pointed file using archie, and retrive it from anywhere",  "put",		Ftp_get,          1,"put <local_file> [<remote_file>] - send server to file",  "mput",		Ftp_mput,         1,"mput <local_file(s)>  - recursive send file(s) to server",  "copy",               Ftp_copy,         1,"copy [<frame>!]file [<frame>!]file - copy file via client cache",  "ccopy",               Ftp_ccopy,       1,"ccopy [<frame>!]file [<frame>!]file - copy file directly beetween servers",  "cat",		Ftp_type,         1,"cat <file> - print body of remote file to screen",    "page",		Ftp_page,         1,"page <file> - print body of remote file to screen via pager",  "bg",			Ftp_bg,           0,"bg <any_command> - run command(s) backgroundly (output redirect to file),\n\You can also add &-char to back of line without \"bg\"",  "archie",             Ftp_acd,       0,"archie - Find file using archie service and display to screen",  "dup",		Ftp_dup,          1,"dup - Make new analogous frame",  "quote",              Ftp_quote,        1,"quote <some_string> - send command directly to server",  "help",		Ftp_help,         0,"help <command> - print list of commands or command description",  "alias",              Ftp_alias,        0,"\alias aliasname <list> .... - make new alias, use $X for taking \n\                  X's argument from command string, and $* for taking\n\                  all arguments. If $<anything> on alias not present,\n\                  the arguments appending to end of command string",  "unalias",            Ftp_unalias,      0,"unalias <aliasname> - remove alias",  "mkalias",            Ftp_mkalias,      0,"mkalias <Alias_name> - make alias for create this frame, use save for saving it to file",  "savealiases",              Ftp_save_aliases,     0,  "savealiases - Save aliases to file",  "savesets",                 Ftp_save_sets,     0,  "savesets - Save sets to file",  "etc",               NULL,         0,  "\1. In any command you may use constructions <file and >file for\n\   redirect input output.\n\\n\2. All local files files interprets as libftp file(s), \n\   this support next specification:\n\\n\   |string - interprets string as shell command, which must be\n\   execute and input or output take from/to it.\n\   \n\\n\   *STDIN*, *STDOUT*, *STDERR* - opened streams.\n\\n\   anything - local file name.\n\\n\3. Command started with '!' passed to shell.\n\n\4. If string beetween two \" or \', its interprets as one word.\n\\n\5. Any string may be devide to few commands using ';'.",  NULL  };

⌨️ 快捷键说明

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