1 /* ftp.c Copyright 1992-2000 by Michael Temari All Rights Reserved
3 * ftp An ftp client program for use with TNET.
7 * Version: 0.10 06/21/92 (pre-release not yet completed)
9 * 0.30 01/15/96 (Minix 1.7.1 initial release)
12 * 1.00 12/12/03 (added ver command)
15 * Author: Michael Temari, <Michael@TemWare.Com>
18 #include <sys/types.h>
31 char *FtpVersion
= "1.01 02/07/05";
43 char *cmdargv
[NUMARGS
];
48 _PROTOTYPE(static void makeargs
, (char *buff
));
49 _PROTOTYPE(int DOver
, (void));
50 _PROTOTYPE(int DOhelp
, (void));
51 _PROTOTYPE(static int getline
, (char *line
, int len
));
52 _PROTOTYPE(int main
, (int argc
, char *argv
[]));
55 static void makeargs(buff
)
61 for(i
= 0; i
< NUMARGS
; i
++)
62 cmdargv
[i
] = (char *)0;
64 p
= buff
+ strlen(buff
) - 1;
66 if(*p
== '\r' || *p
== '\n' || isspace(*p
))
73 while(cmdargc
< NUMARGS
) {
74 while(*p
&& isspace(*p
))
78 cmdargv
[cmdargc
++] = p
;
79 while(*p
&& !isspace(*p
)) {
91 int readline(prompt
, buff
, len
)
98 printf(prompt
); fflush(stdout
);
100 if(fgets(buff
, len
, stdin
) == (char *)NULL
) {
101 printf("\nEnd of file on input!\n");
105 p
= buff
+ strlen(buff
) - 1;
107 if(*p
== '\r' || *p
== '\n' || isspace(*p
))
113 printf("%s\n", buff
);
120 static int getline(line
, len
)
127 /* leave room for at end for null */
130 /* got to be able to put in at least 1 character */
136 s
= read(ftpcomm_fd
, line
, 1);
141 gotcr
= (*line
== '\r');
161 if((s
= getline(reply
, sizeof(reply
))) < 0)
164 printf("%s\n", reply
);
169 strncpy(code
, reply
, 3);
172 } while(strncmp(reply
, code
, 3) || reply
[3] == '-');
174 } while(s
< 200 && s
!= 125 && s
!= 150);
182 printf("You must \"OPEN\" a connection first.\n");
187 printf("You must login first.\n");
194 int DOcommand(ftpcommand
, ftparg
)
202 sprintf(ss
, "%s %s\r\n", ftpcommand
, ftparg
);
204 sprintf(ss
, "%s\r\n", ftpcommand
);
206 s
= write(ftpcomm_fd
, ss
, strlen(ss
));
211 s
= write(ftpcomm_fd
, ftpcommand
, strlen(ftpcommand
));
212 if(s
!= strlen(ftpcommand
))
216 s
= write(ftpcomm_fd
, " ", 1);
220 s
= write(ftpcomm_fd
, ftparg
, strlen(ftparg
));
221 if(s
!= strlen(ftparg
))
225 s
= write(ftpcomm_fd
, "\r\n", 2);
230 return(DOgetreply());
235 printf("FTP Version %s\n", FtpVersion
);
243 printf("Command: Description\n");
244 printf("! Escape to a shell\n");
245 printf("append Append a file to remote host\n");
246 printf("ascii Set file transfer type to ascii\n");
247 printf("binary Set file transfer type to binary\n");
248 printf("block Set file transfer mode to block\n");
249 printf("bye Close connection and exit\n");
250 printf("cd Change directory on remote host\n");
251 printf("close Close connection\n");
252 printf("clone Clone a file\n");
253 printf("del Remove file on remote host\n");
254 printf("dir Display long form remote host directory listing\n");
255 printf("exit Close connection and exit\n");
256 printf("get Retrieve a file from remote host\n");
257 printf("help Display this text\n");
259 if(readline("Press ENTER to continue... ", junk
, sizeof(junk
)))
262 printf("lcd Change directory on local host\n");
263 printf("ldir Display long form local host directory listing\n");
264 printf("lls Display local host directory listing\n");
265 printf("lmkdir Create directory on local host\n");
266 printf("lpwd Display current directory on local host\n");
267 printf("lrmdir Remove directory on local host\n");
268 printf("ls Display remote host directory listing\n");
269 printf("mget Retrieve multiple files from remote host\n");
270 printf("mkdir Create directory on remote host\n");
271 printf("mod Get file modification time\n");
272 printf("mput Send multiple files to remote host\n");
273 printf("noop Send the ftp NOOP command\n");
275 if(readline("Press ENTER to continue... ", junk
, sizeof(junk
)))
278 printf("open Open connection to remote host\n");
279 printf("pass Enter remote user password\n");
280 printf("passive Toggle passive mode\n");
281 printf("put Send a file to remote host\n");
282 printf("putu Send a file to remote host(unique)\n");
283 printf("pwd Display current directory on remote host\n");
284 printf("quit Close connection and exit\n");
285 printf("quote Send raw ftp command to remote host\n");
286 printf("reget Restart a partial file retrieve from remote host\n");
287 printf("remotehelp Display ftp commands implemented on remote host\n");
288 printf("reput Restart a partial file send to remote host\n");
289 printf("rm Remove file on remote host\n");
290 printf("rmdir Remove directory on remote host\n");
292 if(readline("Press ENTER to continue... ", junk
, sizeof(junk
)))
295 printf("site Send a site specific command\n");
296 printf("size Get file size information\n");
297 printf("status Get connection/file status information\n");
298 printf("stream Set file transfer mode to stream\n");
299 printf("system Get remote system type information\n");
300 printf("user Enter remote user information\n");
301 printf("ver Display client version information\n");
308 _PROTOTYPE(int (*func
), (void));
311 static struct commands commands
[] = {
340 "passive", DOpassive
,
347 "remotehelp", DOremotehelp
,
366 struct commands
*cmd
;
367 static char buffer
[128];
377 sprintf(buffer
, "open %s ", argv
[1]);
381 sprintf(buffer
, "user");
388 s
= readline("ftp>", buffer
, sizeof(buffer
));
391 if(cmdargc
== 0) continue;
392 for(cmd
= commands
; *cmd
->name
!= '\0'; cmd
++)
393 if(!strcmp(cmdargv
[0], cmd
->name
))
395 if(*cmd
->name
!= '\0')
399 printf("Command \"%s\" not recognized.\n", cmdargv
[0]);