home *** CD-ROM | disk | FTP | other *** search
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % X X TTTTT PPPP %
- % X X T P P %
- % X T PPPP %
- % X X T P %
- % X X T P %
- % %
- % %
- % File transfer program. %
- % %
- % %
- % %
- % Software Design %
- % John Cristy %
- % February 1989 %
- % %
- % %
- % Copyright 1990 E. I. Dupont de Nemours & Company %
- % %
- % Permission to use, copy, modify, distribute, and sell this software and %
- % its documentation for any purpose is hereby granted without fee, %
- % provided that the above copyright notice appear in all copies and that %
- % both that copyright notice and this permission notice appear in %
- % supporting documentation, and that the name of E. I. Dupont de Nemours %
- % & Company not be used in advertising or publicity pertaining to %
- % distribution of the software without specific, written prior %
- % permission. E. I. Dupont de Nemours & Company makes no representations %
- % about the suitability of this software for any purpose. It is provided %
- % "as is" without express or implied warranty. %
- % %
- % E. I. Dupont de Nemours & Company disclaims all warranties with regard %
- % to this software, including all implied warranties of merchantability %
- % and fitness, in no event shall E. I. Dupont de Nemours & Company be %
- % liable for any special, indirect or consequential damages or any %
- % damages whatsoever resulting from loss of use, data or profits, whether %
- % in an action of contract, negligence or other tortious action, arising %
- % out of or in connection with the use or performance of this software. %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % Xtp is a utility for retrieving, listing, or printing files from a remote
- % network site.
- %
- % This program was adapted from a similiar program written by Steve Singles,
- % University of Delaware.
- %
- % Command syntax:
- %
- % Usage: xtp [-options ...] <host/ip address> [ <home directory> ]
- %
- % Where options include:
- % -binary retrieve files as binary
- % -exclude expression exclude files that match the expression
- % -directory expression list file names that match the expression
- % -ident password specifies password
- % -print expression print files that match the expression
- % -retrieve expression retrieve files that match the expression
- % -timeout seconds specifies maximum seconds to logon host
- % -user name identify yourself to the remote FTP server
- %
- %
- */
-
- /*
- Include declarations.
- */
- #include <stdio.h>
- #include <ctype.h>
- #include <signal.h>
- #include <strings.h>
- #include <sys/file.h>
- #include <sys/types.h>
- #include <sys/time.h>
- #include <sys/socket.h>
- #include <sys/wait.h>
- #include "regular.h"
- /*
- Define declarations.
- */
- #define False 0
- #define True 1
- /*
- Variable declarations.
- */
- char
- *malloc(),
- *program_name,
- *sprintf(),
- *slave_tty[16],
- *Wait();
-
- int
- binary,
- master;
-
- RegularExpression
- *directory_expression,
- *exclude_expression,
- *print_expression,
- *retrieve_expression;
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % D i r e c t o r y R e q u e s t %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- void DirectoryRequest(fileinfo,filename)
- char
- *fileinfo,
- *filename;
- {
- (void) fprintf(stdout,"%s %s\n",fileinfo,filename);
- }
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % E r r o r %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- void Error(error)
- char
- *error;
- {
- char
- message[80];
-
- (void) sprintf(message,"%s: %s",program_name,error);
- perror(message);
- exit(1);
- }
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % E x e c u t e F t p %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- void ExecuteFtp(hostname)
- char
- *hostname;
- {
- #include <sys/ioctl.h>
-
- int
- slave;
-
- struct ltchars
- lc;
-
- struct sgttyb
- b;
-
- struct tchars
- tc;
-
- (void) signal(SIGTSTP,SIG_IGN);
- if (isatty(0))
- {
- int
- tty;
-
- tty=open("/dev/tty",O_RDWR);
- if (tty >= 0)
- {
- (void) ioctl(tty,TIOCNOTTY,(char *) 0);
- (void) close(tty);
- }
- }
- slave=open((char *) slave_tty,O_RDWR);
- if (slave < 0)
- Error((char *) slave_tty);
- /*
- Fix tty line.
- */
- (void) ioctl(slave,TIOCGETP,&b);
- b.sg_flags&=~(ECHO | CRMOD);
- b.sg_erase=(-1);
- b.sg_kill=(-1);
- (void) ioctl(slave,TIOCSETP,&b);
- tc.t_intrc=(-1);
- tc.t_quitc=(-1);
- tc.t_startc=(-1);
- tc.t_stopc=(-1);
- tc.t_eofc=(-1);
- tc.t_brkc=(-1);
- (void) ioctl(slave,TIOCSETC,&tc);
- lc.t_suspc=(-1);
- lc.t_dsuspc=(-1);
- lc.t_rprntc=(-1);
- lc.t_flushc=(-1);
- lc.t_werasc=(-1);
- lc.t_lnextc=(-1);
- (void) ioctl(slave,TIOCSLTC,&lc);
- (void) close(master);
- (void) dup2(slave,0);
- (void) dup2(slave,1);
- (void) dup2(slave,2);
- (void) close(slave);
- (void) execl("/usr/ucb/ftp","ftp","-n","-i","-g",hostname,(char *) 0);
- perror("/usr/ucb/ftp");
- (void) kill(0,SIGTERM);
- }
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % F e t c h R e q u e s t %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- void FetchRequest(filename)
- char
- *filename;
- {
- char
- command[256],
- *p,
- *response;
-
- /*
- get remote-file local-file
- */
- p=filename+strlen(filename);
- while ((p > filename) && (*--p != '/'));
- if (*p == '/')
- p++;
- (void) sprintf(command,"get %s %s\n",filename,p);
- (void) write(master,command,strlen(command));
- (void) fprintf(stdout,"%s retrieved.\n",filename);
- while (response=Wait())
- (void) fprintf(stdout,"%s\n",response);
- }
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % G e t H o s t I n f o %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- void GetHostInfo(host)
- char
- *host;
- {
- #include <netinet/in.h>
- #include <netdb.h>
- #include <arpa/inet.h>
-
- char
- *address,
- *inet_ntoa(),
- *p;
-
- struct in_addr
- in;
-
- struct hostent
- *hp;
-
- if (isdigit(*host))
- {
- /*
- Internet address to name.
- */
- in.s_addr=inet_addr(host);
- hp=gethostbyaddr(&in.s_addr,sizeof(in.s_addr),AF_INET);
- if (hp != (struct hostent *) NULL)
- {
- hp=gethostbyname(hp->h_name);
- if (hp != (struct hostent *) NULL)
- {
- in.s_addr= *(int *) hp->h_addr;
- address=inet_ntoa(in);
- }
- }
- }
- else
- {
- /*
- Internet name to address.
- */
- hp=gethostbyname(host);
- if (hp != (struct hostent *) NULL)
- {
- in.s_addr= *(int *) hp->h_addr;
- address=inet_ntoa(in);
- hp=gethostbyaddr(&in.s_addr,sizeof(in.s_addr),AF_INET);
- }
- }
- if (hp == (struct hostent *) NULL)
- (void) fprintf(stdout,"%s: ",host);
- else
- {
- p=hp->h_name;
- while (*p)
- {
- if (isupper(*p))
- *p=tolower(*p);
- p++;
- }
- (void) fprintf(stdout,"%s [%s]: ",hp->h_name,address);
- }
- }
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % G e t P s e u d o T e r m i n a l %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- void GetPseudoTerminal()
- {
- #include <sys/stat.h>
-
- char
- *master_tty[16];
-
- register char
- *bank,
- *cp;
-
- struct stat
- info;
-
- for (bank="pqrs"; *bank; bank++)
- {
- (void) sprintf((char *) master_tty,"/dev/pty%c0",*bank);
- if (stat(master_tty,&info) < 0)
- break;
- for (cp="0123456789abcdef"; *cp; cp++)
- {
- (void) sprintf((char *) master_tty,"/dev/pty%c%c",*bank,*cp);
- master=open((char *) master_tty,O_RDWR);
- if (master >= 0)
- {
- /*
- Verify slave side is usable.
- */
- (void) sprintf((char *) slave_tty,"/dev/tty%c%c",*bank,*cp);
- if (access((char *) slave_tty,R_OK | W_OK) == 0)
- return;
- (void) close(master);
- }
- }
- }
- Error("All network ports in use.\n");
- }
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % P r i n t R e q u e s t %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- void PrintRequest(filename)
- char
- *filename;
- {
- char
- command[256],
- *response;
-
- /*
- get remote-file [ - | <| zcat> ].
- */
- (void) sprintf(command,"get %s",filename);
- (void) write(master,command,strlen(command));
- if (strcmp(filename+strlen(filename)-2,".Z"))
- (void) sprintf(command," -\n");
- else
- (void) sprintf(command," | zcat\n");
- (void) write(master,command,strlen(command));
- (void) fprintf(stdout,"%s:\n",filename);
- while (response=Wait())
- (void) fprintf(stdout,"%s\n",response);
- }
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % P r o c e s s R e q u e s t %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- void ProcessRequest()
- {
- typedef struct _DirectoryNode
- {
- char
- *info,
- *name;
-
- struct _DirectoryNode
- *next;
- } DirectoryNode;
-
- char
- command[256],
- directory[1024],
- *info,
- *name,
- *response;
-
- DirectoryNode
- *next,
- *root;
-
- int
- unix_filesystem;
-
- register char
- *p;
-
- register DirectoryNode
- **last,
- *node;
-
- RegularExpression
- *expression;
-
- /*
- Initialize function variables.
- */
- root=(DirectoryNode *) NULL;
- last=(&root);
- *directory=(char) NULL;
- unix_filesystem=False;
- /*
- Unix-style filesystem if the first character is a '-' or last is '/'.
- */
- (void) strcpy(command,"dir\n");
- (void) write(master,command,strlen(command));
- response=Wait();
- if (response == (char *) NULL)
- return;
- expression=CompileRegularExpression("[dbclps-][rwx-][rwx-][rwx-]");
- while (response=Wait())
- {
- if (*response == (char) NULL)
- continue;
- if (ExecuteRegularExpression(expression,response))
- unix_filesystem=True;
- }
- free((char *) expression);
- /*
- Issue directory command to ftp program.
- */
- if (unix_filesystem)
- (void) strcpy(command,"dir -R\n");
- else
- (void) strcpy(command,"dir [...]\n");
- (void) write(master,command,strlen(command));
- response=Wait();
- if (response == (char *) NULL)
- return;
- response=Wait();
- if (response == (char *) NULL)
- {
- /*
- Directory command has limited functionality.
- */
- (void) strcpy(command,"dir\n");
- (void) write(master,command,strlen(command));
- response=Wait();
- if (response == (char *) NULL)
- return;
- }
- expression=CompileRegularExpression("Permission denied|not found");
- if (!unix_filesystem)
- while (response=Wait())
- {
- /*
- Link non unix-style file into file list.
- */
- while (*response == ' ')
- response++;
- if (*response == (char) NULL)
- continue;
- p=response;
- while ((*p != ' ') && *p)
- p++;
- if (*p)
- {
- /*
- Extract file info.
- */
- *p++=(char) NULL;
- while (*p == ' ')
- p++;
- }
- info=(char *) malloc((unsigned int) (strlen(p)+1));
- name=(char *) malloc((unsigned int) (strlen(response)+1));
- if ((info == (char *) NULL) || (name == (char *) NULL))
- {
- (void) fprintf(stderr,"Can't continue, not enough memory\n");
- exit(1);
- }
- (void) strcpy(info,p);
- (void) strcpy(name,response);
- if (exclude_expression)
- if (ExecuteRegularExpression(exclude_expression,name))
- {
- (void) free(name);
- (void) free(info);
- continue;
- }
- node=(DirectoryNode *) malloc(sizeof(DirectoryNode));
- if (node == (DirectoryNode *) NULL)
- {
- (void) fprintf(stderr,"Can't continue, not enough memory\n");
- exit(1);
- }
- node->name=name;
- node->info=info;
- node->next=(DirectoryNode *) NULL;
- *last=node;
- last=(&node->next);
- }
- else
- while (response=Wait())
- {
- /*
- Link unix-style file into file list.
- */
- while (*response == ' ')
- response++;
- if (*response == (char) NULL)
- continue;
- p=response+strlen(response)-1;
- if (*response == '-')
- {
- if (ExecuteRegularExpression(expression,response))
- continue;
- /*
- Extract file name; assume date followed by file name.
- */
- response++;
- while (p > response)
- if (*p-- == ' ')
- if (isdigit(*p))
- break;
- while (*++p == ' ');
- p--;
- *p++=(char) NULL;
- info=(char *) malloc((unsigned int) (strlen(response)+1));
- name=(char *) malloc((unsigned int) (strlen(directory)+strlen(p)+1));
- if ((info == (char *) NULL) || (name == (char *) NULL))
- {
- (void) fprintf(stderr,"Can't continue, not enough memory\n");
- exit(1);
- }
- (void) strcpy(info,response);
- (void) strcpy(name,directory);
- (void) strcat(name,p);
- if (exclude_expression)
- if (ExecuteRegularExpression(exclude_expression,name))
- {
- (void) free(name);
- (void) free(info);
- continue;
- }
- node=(DirectoryNode *) malloc(sizeof(DirectoryNode));
- if (node == (DirectoryNode *) NULL)
- {
- (void) fprintf(stderr,"Can't continue, not enough memory\n");
- exit(1);
- }
- node->name=name;
- node->info=info;
- node->next=(DirectoryNode *) NULL;
- *last=node;
- last=(&node->next);
- }
- else
- if (*p == ':')
- {
- /*
- File is a directory.
- */
- *p='/';
- (void) strcpy(directory,response);
- }
- }
- free((char *) expression);
- /*
- Traverse file list.
- */
- node=root;
- while (node)
- {
- if (directory_expression)
- if (ExecuteRegularExpression(directory_expression,node->name))
- (void) DirectoryRequest(node->info,node->name);
- if (retrieve_expression)
- if (ExecuteRegularExpression(retrieve_expression,node->name))
- (void) FetchRequest(node->name);
- if (print_expression)
- if (ExecuteRegularExpression(print_expression,node->name))
- (void) PrintRequest(node->name);
- /*
- Free allocated memory for this node.
- */
- (void) free(node->info);
- (void) free(node->name);
- next=node->next;
- (void) free((char *) node);
- node=next;
- }
- }
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % S i g n a l C h i l d %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- void SignalChild()
- {
- char
- message[256];
-
- int
- status;
-
- (void) sprintf(message,"child died, status %x",wait(&status));
- Error(message);
- }
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % U s a g e %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % Procedure Usage displays the program usage;
- %
- % The format of the Usage routine is:
- %
- % Usage(message)
- %
- % A description of each parameter follows:
- %
- % o message: Specifies a specific message to display to the user.
- %
- %
- */
- void Usage(message)
- char
- *message;
- {
- char
- **p;
-
- static char
- *options[]=
- {
- "-binary retrieve files as binary",
- "-exclude expression exclude files that match the expression",
- "-directory expression list file names that match the expression",
- "-ident password specifies password",
- "-print expression print files that match the expression",
- "-retrieve expression retrieve files that match the expression",
- "-timeout seconds specifies maximum seconds to logon host",
- "-user name identify yourself to the remote FTP server",
- "-verbose show all responses from the remote server",
- NULL
- };
- if (message)
- (void) fprintf(stderr,"Can't continue, %s\n\n",message);
- (void) fprintf(stderr,
- "Usage: %s [-options ...] <host/ip address> [ <home directory> ]\n",
- program_name);
- (void) fprintf(stderr,"\nWhere options include:\n");
- for (p=options; *p; *p++)
- (void) fprintf(stderr," %s\n",*p);
- exit(1);
- }
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % W a i t %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- char *Wait()
- {
- register char
- *p;
-
- static char
- buffer[1024],
- *q;
-
- static char
- line[1024];
-
- static int
- count=0;
-
- p=line;
- do
- {
- if (count <= 0)
- {
- count=read(master,buffer,sizeof(buffer));
- q=buffer;
- if (count <= 0)
- {
- if (p == line)
- return((char *) NULL);
- break;
- }
- }
- count--;
- *p=(*q++);
- if (*p == '\n')
- break;
- p++;
- if ((p-line) >= 5)
- if (!strncmp(p-5,"ftp> ",5))
- if (count == 0)
- return((char *) NULL);
- } while (p < (line+sizeof(line)));
- *p=(char) NULL;
- return(line);
- }
-
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % m a i n %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- main(argc,argv)
- int
- argc;
-
- register char
- **argv;
- {
- char
- command[256],
- *ident,
- *home_directory,
- *hostname,
- *user;
-
- int
- child,
- status;
-
- register char
- *p;
-
- unsigned int
- timeout,
- verbose;
-
- /*
- Initialize program variables.
- */
- binary=False;
- directory_expression=(RegularExpression *) NULL;
- exclude_expression=(RegularExpression *) NULL;
- ident=(char *) NULL;
- print_expression=(RegularExpression *) NULL;
- retrieve_expression=(RegularExpression *) NULL;
- timeout=0;
- user=(char *) NULL;
- program_name=argv[0];
- verbose=False;
- /*
- Parse command line arguments.
- */
- for (p=(*argv++); *argv && (**argv == '-'); argv++)
- switch (argv[0][1])
- {
- case 'b':
- {
- binary++;
- break;
- }
- case 'd':
- {
- directory_expression=CompileRegularExpression(*++argv);
- if (!directory_expression)
- exit(1);
- break;
- }
- case 'e':
- {
- exclude_expression=CompileRegularExpression(*++argv);
- if (!exclude_expression)
- exit(1);
- break;
- }
- case 'i':
- {
- ident=(*++argv);
- break;
- }
- case 'p':
- {
- print_expression=CompileRegularExpression(*++argv);
- if (!print_expression)
- exit(1);
- break;
- }
- case 'r':
- {
- retrieve_expression=CompileRegularExpression(*++argv);
- if (!retrieve_expression)
- exit(1);
- break;
- }
- case 't':
- {
- timeout=atoi(*++argv);
- break;
- }
- case 'u':
- {
- user=(*++argv);
- break;
- }
- case 'v':
- {
- verbose++;
- break;
- }
- default:
- {
- Usage((char *) NULL);
- break;
- }
- }
- if ((argc < 2) || (*argv == (char *) NULL))
- Usage((char *) NULL);
- hostname=argv[0];
- home_directory=argv[1];
- if (!directory_expression && !retrieve_expression && !print_expression)
- directory_expression=CompileRegularExpression("");
- if ((ident == (char *) NULL) && (user == (char *) NULL))
- {
- static char
- name[256];
-
- /*
- Identify user as user@host.domain.
- */
- if (getlogin())
- (void) strcpy(name,getlogin());
- else
- (void) strcpy(name,getpwuid(getuid()));
- p=name+strlen(name);
- *p++='@';
- (void) gethostname(p,64);
- while (*p)
- p++;
- (void) getdomainname(p,64);
- user="anonymous";
- ident=name;
- }
- else
- if (ident == (char *) NULL)
- ident=(char *) getpass("Password: ");
- else
- user="anonymous";
- (void) GetHostInfo(hostname);
- if (!home_directory)
- (void) fprintf(stdout,"\n");
- else
- (void) fprintf(stdout,"%s\n",home_directory);
- (void) GetPseudoTerminal();
- /*
- Connect and logon to host.
- */
- (void) signal(SIGCHLD,SignalChild);
- if (timeout > 0)
- (void) alarm(timeout); /* enable timer. */
- child=fork();
- if (child < 0)
- Error("fork");
- if (child == 0)
- ExecuteFtp(hostname);
- while (p=Wait())
- (void) fprintf(stderr,"%s\n",p);
- (void) sprintf(command,"user %s %s\n",user,ident);
- (void) write(master,command,strlen(command));
- while (p=Wait())
- (void) fprintf(stderr,"%s\n",p);
- if (timeout > 0)
- (void) alarm(0); /* disable timer. */
- (void) fprintf(stderr,"\n");
- if (!verbose)
- {
- (void) strcpy(command,"verbose off\n");
- (void) write(master,command,strlen(command));
- while (Wait());
- }
- if (home_directory)
- {
- /*
- Change remote working directory.
- */
- (void) sprintf(command,"cd %s\n",home_directory);
- (void) write(master,command,strlen(command));
- while (Wait());
- (void) strcpy(command,"pwd\n");
- (void) write(master,command,strlen(command));
- while (p=Wait())
- (void) fprintf(stderr,"%s\n",p);
- }
- if (binary)
- {
- /*
- Set file transfer type.
- */
- (void) strcpy(command,"type binary\n");
- (void) write(master,command,strlen(command));
- while (Wait());
- (void) write(master,command,strlen(command));
- (void) strcpy(command,"type\n");
- while (p=Wait())
- (void) fprintf(stderr,"%s\n",p);
- }
- (void) strcpy(command,"runique\n");
- (void) write(master,command,strlen(command));
- while (Wait());
- ProcessRequest();
- (void) strcpy(command,"quit\n");
- (void) write(master,command,strlen(command));
- (void) signal(SIGCHLD,SIG_DFL);
- /*
- Wait for child to finish.
- */
- while (child != wait(&status));
- (void) close(master);
- free((char *) directory_expression);
- free((char *) exclude_expression);
- free((char *) print_expression);
- free((char *) retrieve_expression);
- return(0);
- }
-