static char sccsid
[] = "@(#)cmds.c 4.2 (Berkeley) 2/21/83";
* FTP User Program -- Command Routines.
* Connect to peer server and
* auto-login, if possible.
struct hostent
*host
, *hookup();
printf("Already connected to %s, use disconnect first.\n",
gets(&line
[strlen(line
)]);
printf("usage: %s host-name [port]\n", argv
[0]);
printf("%s: bad port number-- %s\n", argv
[1], argv
[2]);
printf ("usage: %s host-name [port]\n", argv
[0]);
host
= hookup(argv
[1], port
);
{ "ascii", "A", TYPE_A
, 0 },
{ "binary", "I", TYPE_I
, 0 },
{ "image", "I", TYPE_I
, 0 },
{ "ebcdic", "E", TYPE_E
, 0 },
{ "tenex", "L", TYPE_L
, bytename
},
register struct types
*p
;
printf("usage: %s [", argv
[0]);
for (p
= types
; p
->t_name
; p
++) {
printf("%s%s", sep
, p
->t_name
);
printf("Using %s mode to transfer files.\n", typename
);
for (p
= types
; p
->t_name
; p
++)
if (strcmp(argv
[1], p
->t_name
) == 0)
printf("%s: unknown mode\n", argv
[1]);
if ((p
->t_arg
!= NULL
) && (*(p
->t_arg
) != '\0'))
comret
= command ("TYPE %s %s", p
->t_mode
, p
->t_arg
);
comret
= command("TYPE %s", p
->t_mode
);
if (comret
== COMPLETE
) {
strcpy(typename
, p
->t_name
);
* Set binary transfer type.
call(settype
, "type", "binary", 0);
* Set ascii transfer type.
call(settype
, "type", "ascii", 0);
* Set tenex transfer type.
call(settype
, "type", "tenex", 0);
* Set ebcdic transfer type.
call(settype
, "type", "ebcdic", 0);
* Set file transfer mode.
printf("We only support %s mode, sorry.\n", modename
);
* Set file transfer format.
printf("We only support %s format, sorry.\n", formname
);
* Set file transfer structure.
printf("We only support %s structure, sorry.\n", structname
);
register char *cp
, *targ
;
printf("Not connected.\n");
argc
++, argv
[2] = argv
[1];
gets(&line
[strlen(line
)]);
printf("%s local-file remote-file\n", argv
[0]);
printf("(remote-file) ");
gets(&line
[strlen(line
)]);
sendrequest("STOR", argv
[1], argv
[2]);
printf("Not connected.\n");
argc
++, argv
[2] = argv
[1];
printf("(remote-file) ");
gets(&line
[strlen(line
)]);
printf("%s remote-file local-file\n", argv
[0]);
gets(&line
[strlen(line
)]);
recvrequest("RETR", argv
[2], argv
[1]);
return (bool ? "on" : "off");
printf("Connected to %s.\n", hostname
);
printf("Not connected.\n");
printf("Mode: %s; Type: %s; Form: %s; Structure: %s\n",
modename
, typename
, formname
, structname
);
printf("Verbose: %s; Bell: %s; Prompting: %s\n",
onoff(verbose
), onoff(bell
), onoff(interactive
));
* Set beep on cmd completed mode.
printf("Bell mode %s.\n", onoff(bell
));
* Turn on packet tracing.
printf("Packet tracing %s.\n", onoff(trace
));
* Turn on printing of server echo's.
printf("Verbose mode %s.\n", onoff(verbose
));
* Turn on interactive prompting
* during mget, mput, and mdelete.
interactive
= !interactive
;
printf("Interactive mode %s.\n", onoff(interactive
));
* Set debugging mode on/off and/or
* set level of debugging.
printf("%s: bad debugging value.\n", argv
[1]);
printf("Debugging %s (debug=%d).\n", onoff(debug
), debug
);
* Set current working directory
printf("Not connected.\n");
printf("(remote-directory) ");
gets(&line
[strlen(line
)]);
printf("%s remote-directory\n", argv
[0]);
(void) command("CWD %s", argv
[1]);
* Set current working directory
static struct passwd
*pw
= NULL
;
pw
= getpwnam(getlogin());
printf("ftp: can't find home directory.\n");
argc
++, argv
[1] = pw
->pw_dir
;
printf("%s local-directory\n", argv
[0]);
printf("(remote-file) ");
gets(&line
[strlen(line
)]);
printf("%s remote-file\n", argv
[0]);
(void) command("DELE %s", argv
[1]);
gets(&line
[strlen(line
)]);
printf("%s from-name to-name\n", argv
[0]);
gets(&line
[strlen(line
)]);
if (command("RNFR %s", argv
[1]) == CONTINUE
)
(void) command("RNTO %s", argv
[2]);
* Get a directory listing
printf("usage: %s remote-directory local-file\n", argv
[0]);
cmd
= argv
[0][0] == 'l' ? "NLST" : "LIST";
recvrequest(cmd
, argv
[2], argv
[1]);
printf("Sorry, this function is unimplemented.\n");
* Send new user information (re-login)
char acct
[80], *getpass();
gets(&line
[strlen(line
)]);
printf("usage: %s username [password] [account]\n", argv
[0]);
n
= command("USER %s", argv
[1]);
argv
[2] = getpass("Password: "), argc
++;
n
= command("PASS %s", argv
[2]);
printf("Account: "); (void) fflush(stdout
);
(void) fgets(acct
, sizeof(acct
) - 1, stdin
);
acct
[strlen(acct
) - 1] = '\0';
n
= command("ACCT %s", acct
);
fprintf(stderr
, "Login failed.\n");
* Print working directory.
printf("Not connected.\n");
printf("(directory-name) ");
gets(&line
[strlen(line
)]);
printf("%s directory-name\n", argv
[0]);
(void) command("XMKD %s", argv
[1]);
printf("(directory-name) ");
gets(&line
[strlen(line
)]);
printf("%s directory-name\n", argv
[0]);
(void) command("XRMD %s", argv
[1]);
* Send a line, verbatim, to the remote machine.
printf("(command line to send) ");
gets(&line
[strlen(line
)]);
printf("usage: %s line-to-send\n", argv
[0]);
for (i
= 2; i
< argc
; i
++) {
* Ask the other side for help.
int oldverbose
= verbose
;
(void) command(argc
== 1 ? "HELP" : "HELP %s", argv
[1]);
* Terminate session and exit.
* Terminate session, but don't exit.