static char sccsid
[] = "@(#)cmds.c 4.9 (Berkeley) %G%";
* 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
);
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
)]);
if (!globulize(&argv
[1]))
cmd
= (argv
[0][0] == 'a') ? "APPE" : "STOR";
sendrequest(cmd
, argv
[1], argv
[2]);
printf("(local-files) ");
gets(&line
[strlen(line
)]);
printf("%s local-files\n", argv
[0]);
for (i
= 1; i
< argc
; i
++) {
register char **cpp
, **gargs
;
if (confirm(argv
[0], argv
[i
]))
sendrequest("STOR", argv
[i
], argv
[i
]);
for (cpp
= gargs
; cpp
&& *cpp
!= NULL
; cpp
++)
if (confirm(argv
[0], *cpp
))
sendrequest("STOR", *cpp
, *cpp
);
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
)]);
if (!globulize(&argv
[2]))
recvrequest("RETR", argv
[2], argv
[1], "w");
printf("(remote-files) ");
gets(&line
[strlen(line
)]);
printf("%s remote-files\n", argv
[0]);
while ((cp
= remglob(argc
, argv
)) != NULL
)
if (confirm(argv
[0], cp
))
recvrequest("RETR", cp
, cp
, "w");
static char buf
[MAXPATHLEN
];
static FILE *ftemp
= NULL
;
if ((cp
= *++args
) == NULL
)
strcpy(temp
, "/tmp/ftpXXXXXX");
oldverbose
= verbose
, verbose
= 0;
oldhash
= hash
, hash
= 0;
for (mode
= "w"; *++argv
!= NULL
; mode
= "a")
recvrequest ("NLST", temp
, *argv
, mode
);
verbose
= oldverbose
; hash
= oldhash
;
ftemp
= fopen(temp
, "r");
printf("can't find list of remote files, oops\n");
if (fgets(buf
, sizeof (buf
), ftemp
) == NULL
) {
fclose(ftemp
), ftemp
= NULL
;
if ((cp
= index(buf
, '\n')) != NULL
)
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; Globbing: %s\n",
onoff(verbose
), onoff(bell
), onoff(interactive
),
printf("Hash mark printing: %s; Use of PORT cmds: %s\n",
onoff(hash
), onoff(sendport
));
* Set beep on cmd completed mode.
printf("Bell mode %s.\n", onoff(bell
));
* Turn on packet tracing.
printf("Packet tracing %s.\n", onoff(trace
));
* Toggle hash mark printing during transfers.
printf("Hash mark printing %s", onoff(hash
));
printf(" (%d bytes/hash mark)", BUFSIZ
);
* Turn on printing of server echo's.
printf("Verbose mode %s.\n", onoff(verbose
));
* Toggle PORT cmd use before each data connection.
printf("Use of PORT cmds %s.\n", onoff(sendport
));
* Turn on interactive prompting
* during mget, mput, and mdelete.
interactive
= !interactive
;
printf("Interactive mode %s.\n", onoff(interactive
));
* Toggle metacharacter interpretation
printf("Globbing %s.\n", onoff(doglob
));
* 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("(remote-directory) ");
gets(&line
[strlen(line
)]);
printf("%s remote-directory\n", argv
[0]);
(void) command("CWD %s", argv
[1]);
* Set current working directory
printf("%s local-directory\n", argv
[0]);
if (!globulize(&argv
[1]))
if (chdir(argv
[1]) < 0) {
printf("Local directory now %s\n", getwd(buf
));
printf("(remote-file) ");
gets(&line
[strlen(line
)]);
printf("%s remote-file\n", argv
[0]);
(void) command("DELE %s", argv
[1]);
printf("(remote-files) ");
gets(&line
[strlen(line
)]);
printf("%s remote-files\n", argv
[0]);
while ((cp
= remglob(argc
, argv
)) != NULL
)
if (confirm(argv
[0], cp
))
(void) command("DELE %s", cp
);
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";
if (strcmp(argv
[2], "-") && !globulize(&argv
[2]))
recvrequest(cmd
, argv
[2], argv
[1], "w");
* Get a directory listing
* of multiple remote files.
char *cmd
, *mode
, *cp
, *dest
;
printf("(remote-files) ");
gets(&line
[strlen(line
)]);
gets(&line
[strlen(line
)]);
printf("%s remote-files local-file\n", argv
[0]);
if (globulize(&dest
) && confirm("local-file", dest
))
cmd
= argv
[0][1] == 'l' ? "NLST" : "LIST";
for (mode
= "w"; cp
= remglob(argc
, argv
); mode
= "a")
if (confirm(argv
[0], cp
))
recvrequest(cmd
, dest
, cp
, mode
);
int pid
, status
, (*old1
)(), (*old2
)();
char shellnam
[40], *shell
, *namep
;
old1
= signal (SIGINT
, SIG_IGN
);
old2
= signal (SIGQUIT
, SIG_IGN
);
if ((pid
= fork()) == 0) {
for (pid
= 3; pid
< 20; pid
++)
signal(SIGQUIT
, SIG_DFL
);
namep
= rindex(shell
,'/');
strcat(shellnam
, ++namep
);
if (strcmp(namep
, "sh") != 0)
execl(shell
, shellnam
, 0);
if ((gargs
= glob(cpp
)) != NULL
)
register char **zip
= cpp
;
while (wait(&status
) != pid
)
perror("Try again later");
* 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("(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.
printf("%s %s? ", cmd
, file
);
return (*line
!= 'n' && *line
!= 'N');
fprintf(stderr
, "ftp: %s\n");
* Glob a local file name specification with
* the expectation of a single return value.
* Can't control multiple values being expanded
* from the expression, we return only the first.
printf("%s: %s\n", *cpp
, globerr
);
/* don't waste too much memory */