1 | /* other.c by Michael Temari 06/21/92
|
---|
2 | *
|
---|
3 | * ftp An ftp client program for use with TNET.
|
---|
4 | *
|
---|
5 | * Author: Michael Temari, <temari@ix.netcom.com>
|
---|
6 | */
|
---|
7 |
|
---|
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>
|
---|
15 |
|
---|
16 | #include "ftp.h"
|
---|
17 | #include "other.h"
|
---|
18 |
|
---|
19 | void FTPinit()
|
---|
20 | {
|
---|
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);
|
---|
29 | }
|
---|
30 |
|
---|
31 | int DOpass()
|
---|
32 | {
|
---|
33 | int s;
|
---|
34 | struct termios oldtty, newtty;
|
---|
35 | char *pass;
|
---|
36 | char password[64];
|
---|
37 |
|
---|
38 | if(!linkopen) {
|
---|
39 | printf("You must \"OPEN\" a connection first.\n");
|
---|
40 | return(0);
|
---|
41 | }
|
---|
42 |
|
---|
43 | pass = cmdargv[1];
|
---|
44 |
|
---|
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;
|
---|
54 | }
|
---|
55 |
|
---|
56 | s = DOcommand("PASS", pass);
|
---|
57 |
|
---|
58 | if(s == 230)
|
---|
59 | loggedin = 1;
|
---|
60 |
|
---|
61 | return(s);
|
---|
62 | }
|
---|
63 |
|
---|
64 | int DOuser()
|
---|
65 | {
|
---|
66 | char *user;
|
---|
67 | int s;
|
---|
68 | char username[64];
|
---|
69 |
|
---|
70 | if(!linkopen) {
|
---|
71 | printf("You must \"OPEN\" a connection first.\n");
|
---|
72 | return(0);
|
---|
73 | }
|
---|
74 |
|
---|
75 | loggedin = 0;
|
---|
76 |
|
---|
77 | user = cmdargv[1];
|
---|
78 |
|
---|
79 | if(cmdargc < 2) {
|
---|
80 | readline("Username: ", username, sizeof(username));
|
---|
81 | user = username;
|
---|
82 | }
|
---|
83 |
|
---|
84 | s = DOcommand("USER", user);
|
---|
85 |
|
---|
86 | if(atty && s == 331) {
|
---|
87 | cmdargv[0] = "password";
|
---|
88 | cmdargc = 1;
|
---|
89 | return(DOpass());
|
---|
90 | }
|
---|
91 |
|
---|
92 | if(s == 230)
|
---|
93 | loggedin = 1;
|
---|
94 |
|
---|
95 | return(s);
|
---|
96 | }
|
---|
97 |
|
---|
98 | int DOnoop()
|
---|
99 | {
|
---|
100 | if(DOcmdcheck())
|
---|
101 | return(0);
|
---|
102 |
|
---|
103 | return(DOcommand("NOOP", ""));
|
---|
104 | }
|
---|
105 |
|
---|
106 | int DOpassive()
|
---|
107 | {
|
---|
108 | passive = 1 - passive;
|
---|
109 |
|
---|
110 | printf("Passive mode is now %s\n", (passive ? "ON" : "OFF"));
|
---|
111 |
|
---|
112 | return(0);
|
---|
113 | }
|
---|
114 |
|
---|
115 | int DOsyst()
|
---|
116 | {
|
---|
117 | if(DOcmdcheck())
|
---|
118 | return(0);
|
---|
119 |
|
---|
120 | return(DOcommand("SYST", ""));
|
---|
121 | }
|
---|
122 |
|
---|
123 | int DOremotehelp()
|
---|
124 | {
|
---|
125 | if(!linkopen) {
|
---|
126 | printf("You must \"OPEN\" a connection first.\n");
|
---|
127 | return(0);
|
---|
128 | }
|
---|
129 |
|
---|
130 | return(DOcommand("HELP", ""));
|
---|
131 | }
|
---|
132 |
|
---|
133 | int DOquote()
|
---|
134 | {
|
---|
135 | int i;
|
---|
136 | static char args[512];
|
---|
137 |
|
---|
138 | args[0] = '\0';
|
---|
139 |
|
---|
140 | for(i = 2; i < cmdargc; i++) {
|
---|
141 | if(i != 2)
|
---|
142 | strcat(args, " ");
|
---|
143 | strcat(args, cmdargv[i]);
|
---|
144 | }
|
---|
145 |
|
---|
146 | return(DOcommand(cmdargv[1], args));
|
---|
147 | }
|
---|
148 |
|
---|
149 | int DOsite()
|
---|
150 | {
|
---|
151 | int i;
|
---|
152 | static char args[512];
|
---|
153 |
|
---|
154 | args[0] = '\0';
|
---|
155 |
|
---|
156 | for(i = 1; i < cmdargc; i++) {
|
---|
157 | if(i != 1)
|
---|
158 | strcat(args, " ");
|
---|
159 | strcat(args, cmdargv[i]);
|
---|
160 | }
|
---|
161 |
|
---|
162 | return(DOcommand("SITE", args));
|
---|
163 | }
|
---|