improve behaviour under VPC, fixes from nicolas tittley.
[minix.git] / commands / ftp / other.c
blob249797c00713283b714afa3ea7df8a8bff0e7a07
1 /* other.c by Michael Temari 06/21/92
3 * ftp An ftp client program for use with TNET.
5 * Author: Michael Temari, <temari@ix.netcom.com>
6 */
8 #include <sys/types.h>
9 #include <stdio.h>
10 #include <ctype.h>
11 #include <unistd.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <termios.h>
16 #include "ftp.h"
17 #include "other.h"
19 void FTPinit()
21 linkopen = 0;
22 loggedin = 0;
23 type = TYPE_A;
24 format = 0;
25 mode = 0;
26 structure = 0;
27 passive = 0;
28 atty = isatty(0);
31 int DOpass()
33 int s;
34 struct termios oldtty, newtty;
35 char *pass;
36 char password[64];
38 if(!linkopen) {
39 printf("You must \"OPEN\" a connection first.\n");
40 return(0);
43 pass = cmdargv[1];
45 if(cmdargc < 2) {
46 tcgetattr(fileno(stdout), &oldtty);
47 newtty = oldtty;
48 newtty.c_lflag &= ~ECHO;
49 tcsetattr(fileno(stdout), TCSANOW, &newtty);
50 readline("Password: ", password, sizeof(password));
51 tcsetattr(fileno(stdout), TCSANOW, &oldtty);
52 printf("\n");
53 pass = password;
56 s = DOcommand("PASS", pass);
58 if(s == 230)
59 loggedin = 1;
61 return(s);
64 int DOuser()
66 char *user;
67 int s;
68 char username[64];
70 if(!linkopen) {
71 printf("You must \"OPEN\" a connection first.\n");
72 return(0);
75 loggedin = 0;
77 user = cmdargv[1];
79 if(cmdargc < 2) {
80 readline("Username: ", username, sizeof(username));
81 user = username;
84 s = DOcommand("USER", user);
86 if(atty && s == 331) {
87 cmdargv[0] = "password";
88 cmdargc = 1;
89 return(DOpass());
92 if(s == 230)
93 loggedin = 1;
95 return(s);
98 int DOnoop()
100 if(DOcmdcheck())
101 return(0);
103 return(DOcommand("NOOP", ""));
106 int DOpassive()
108 passive = 1 - passive;
110 printf("Passive mode is now %s\n", (passive ? "ON" : "OFF"));
112 return(0);
115 int DOsyst()
117 if(DOcmdcheck())
118 return(0);
120 return(DOcommand("SYST", ""));
123 int DOremotehelp()
125 if(!linkopen) {
126 printf("You must \"OPEN\" a connection first.\n");
127 return(0);
130 return(DOcommand("HELP", ""));
133 int DOquote()
135 int i;
136 static char args[512];
138 args[0] = '\0';
140 for(i = 2; i < cmdargc; i++) {
141 if(i != 2)
142 strcat(args, " ");
143 strcat(args, cmdargv[i]);
146 return(DOcommand(cmdargv[1], args));
149 int DOsite()
151 int i;
152 static char args[512];
154 args[0] = '\0';
156 for(i = 1; i < cmdargc; i++) {
157 if(i != 1)
158 strcat(args, " ");
159 strcat(args, cmdargv[i]);
162 return(DOcommand("SITE", args));