* Copyright (c) 1985, 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
* FTP User Program -- Command Routines.
* `Another' gets another argument, and stores the new argc and argv.
* It reverts to the top level (via main.c's intr()) on EOF/error.
* Returns false if no new arguments have been added.
another(pargc
, pargv
, prompt
)
int len
= strlen(line
), ret
;
if (len
>= sizeof(line
) - 3) {
printf("sorry, arguments too long\n");
if (fgets(&line
[len
], sizeof(line
) - len
, stdin
) == NULL
)
len
+= strlen(&line
[len
]);
if (len
> 0 && line
[len
- 1] == '\n')
* Connect to peer server and
* auto-login, if possible.
printf("Already connected to %s, use close first.\n",
(void) another(&argc
, &argv
, "to");
if (argc
< 2 || argc
> 3) {
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
);
* Set up defaults for FTP.
(void) strcpy(typename
, "ascii"), type
= TYPE_A
;
(void) strcpy(formname
, "non-print"), form
= FORM_N
;
(void) strcpy(modename
, "stream"), mode
= MODE_S
;
(void) strcpy(structname
, "file"), stru
= STRU_F
;
(void) strcpy(bytename
, "8"), bytesize
= 8;
#if defined(unix) && NBBY == 8
* this ifdef is to keep someone form "porting" this to an incompatible
* system and not checking this out. This way they have to think about it.
if (command("SYST") == COMPLETE
&& overbose
) {
cp
= strchr(reply_string
+4, ' ');
cp
= strchr(reply_string
+4, '\r');
printf("Remote system type is %s.\n",
if (!strncmp(reply_string
, "215 UNIX Type: L8", 17)) {
* Set type to 0 (not specified by user),
* meaning binary by default, but don't bother
* telling server. We can use binary
* for text files unless changed by the user.
(void) strcpy(typename
, "binary");
printf("Using %s mode to transfer files.\n",
!strncmp(reply_string
, "215 TOPS20", 10))
"Remember to set tenex mode when transfering binary files from this machine.\n");
{ "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
},
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
) {
(void) strcpy(typename
, p
->t_name
);
curtype
= type
= p
->t_type
;
* Internal form of settype; changes current type in use with server
* without changing our notion of the type for data transfers.
* Used to change to and from ascii for listings.
changetype(newtype
, show
)
int comret
, oldverbose
= verbose
;
if (debug
== 0 && show
== 0)
for (p
= types
; p
->t_name
; p
++)
if (newtype
== p
->t_type
)
printf("ftp: internal error: unknown type %d\n", newtype
);
if (newtype
== TYPE_L
&& bytename
[0] != '\0')
comret
= command("TYPE %s %s", p
->t_mode
, bytename
);
comret
= command("TYPE %s", p
->t_mode
);
* Set binary transfer type.
* Set ascii transfer type.
* Set tenex transfer type.
* 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
);
char *oldargv1
, *oldargv2
;
if (argc
< 2 && !another(&argc
, &argv
, "local-file"))
if (argc
< 3 && !another(&argc
, &argv
, "remote-file")) {
printf("usage: %s local-file remote-file\n", argv
[0]);
if (!globulize(&argv
[1])) {
* If "globulize" modifies argv[1], and argv[2] is a copy of
* the old argv[1], make it a copy of the new argv[1].
if (argv
[1] != oldargv1
&& argv
[2] == oldargv1
) {
cmd
= (argv
[0][0] == 'a') ? "APPE" : ((sunique
) ? "STOU" : "STOR");
argv
[2] = dotrans(argv
[2]);
argv
[2] = domap(argv
[2]);
sendrequest(cmd
, argv
[1], argv
[2],
argv
[1] != oldargv1
|| argv
[2] != oldargv2
);
if (argc
< 2 && !another(&argc
, &argv
, "local-files")) {
printf("usage: %s local-files\n", argv
[0]);
oldintr
= signal(SIGINT
, mabort
);
char *cp
, *tp2
, tmpbuf
[MAXPATHLEN
];
while ((cp
= remglob(argv
,0)) != NULL
) {
if (mflag
&& confirm(argv
[0], cp
)) {
while (*tp
&& !islower(*tp
)) {
while ((*tp2
= *tp
) != NULL
) {
sendrequest((sunique
) ? "STOU" : "STOR",
cp
, tp
, cp
!= tp
|| !interactive
);
if (!mflag
&& fromatty
) {
if (confirm("Continue with","mput")) {
(void) signal(SIGINT
, oldintr
);
for (i
= 1; i
< argc
; i
++) {
if (mflag
&& confirm(argv
[0], argv
[i
])) {
tp
= (ntflag
) ? dotrans(argv
[i
]) : argv
[i
];
tp
= (mapflag
) ? domap(tp
) : tp
;
sendrequest((sunique
) ? "STOU" : "STOR",
argv
[i
], tp
, tp
!= argv
[i
] || !interactive
);
if (!mflag
&& fromatty
) {
if (confirm("Continue with","mput")) {
memset(&gl
, 0, sizeof(gl
));
flags
= GLOB_BRACE
|GLOB_NOCHECK
|GLOB_QUOTE
|GLOB_TILDE
;
if (glob(argv
[i
], flags
, NULL
, &gl
) || gl
.gl_pathc
== 0) {
warnx("%s: not found", argv
[i
]);
for (cpp
= gl
.gl_pathv
; cpp
&& *cpp
!= NULL
; cpp
++) {
if (mflag
&& confirm(argv
[0], *cpp
)) {
tp
= (ntflag
) ? dotrans(*cpp
) : *cpp
;
tp
= (mapflag
) ? domap(tp
) : tp
;
sendrequest((sunique
) ? "STOU" : "STOR",
*cpp
, tp
, *cpp
!= tp
|| !interactive
);
if (!mflag
&& fromatty
) {
if (confirm("Continue with","mput")) {
(void) signal(SIGINT
, oldintr
);
(void) getit(argc
, argv
, 1, "r+w");
(void) getit(argc
, argv
, 0, restart_point
? "r+w" : "w" );
getit(argc
, argv
, restartit
, mode
)
char *oldargv1
, *oldargv2
;
if (argc
< 2 && !another(&argc
, &argv
, "remote-file"))
if (argc
< 3 && !another(&argc
, &argv
, "local-file")) {
printf("usage: %s remote-file [ local-file ]\n", argv
[0]);
if (!globulize(&argv
[2])) {
char *tp
= argv
[1], *tp2
, tmpbuf
[MAXPATHLEN
];
while (*tp
&& !islower(*tp
)) {
while ((*tp2
= *tp
) != NULL
) {
argv
[2] = dotrans(argv
[2]);
argv
[2] = domap(argv
[2]);
ret
= stat(argv
[2], &stbuf
);
warn("local: %s", argv
[2]);
restart_point
= stbuf
.st_size
;
if (command("MDTM %s", argv
[1]) == COMPLETE
) {
int yy
, mo
, day
, hour
, min
, sec
;
"%*s %04d%02d%02d%02d%02d%02d",
&yy
, &mo
, &day
, &hour
, &min
, &sec
);
tm
= gmtime(&stbuf
.st_mtime
);
if (tm
->tm_year
> yy
%100)
if ((tm
->tm_year
== yy
%100 &&
printf("%s\n", reply_string
);
recvrequest("RETR", argv
[2], argv
[1], mode
,
argv
[1] != oldargv1
|| argv
[2] != oldargv2
);
if (confirm("Continue with", mname
)) {
char *cp
, *tp
, *tp2
, tmpbuf
[MAXPATHLEN
];
if (argc
< 2 && !another(&argc
, &argv
, "remote-files")) {
printf("usage: %s remote-files\n", argv
[0]);
oldintr
= signal(SIGINT
, mabort
);
while ((cp
= remglob(argv
,proxy
)) != NULL
) {
if (mflag
&& confirm(argv
[0], cp
)) {
for (tp2
= tmpbuf
; ch
= *tp
++;)
*tp2
++ = isupper(ch
) ? tolower(ch
) : ch
;
recvrequest("RETR", tp
, cp
, "w",
tp
!= cp
|| !interactive
);
if (!mflag
&& fromatty
) {
if (confirm("Continue with","mget")) {
(void) signal(SIGINT
,oldintr
);
static char buf
[MAXPATHLEN
];
static FILE *ftemp
= NULL
;
if ((cp
= *++args
) == NULL
)
(void) strcpy(temp
, _PATH_TMP
);
oldverbose
= verbose
, verbose
= 0;
oldhash
= hash
, hash
= 0;
for (mode
= "w"; *++argv
!= NULL
; mode
= "a")
recvrequest ("NLST", temp
, *argv
, mode
, 0);
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
) {
(void) fclose(ftemp
), ftemp
= NULL
;
if ((cp
= strchr(buf
, '\n')) != NULL
)
return (bool ? "on" : "off");
printf("Connected to %s.\n", hostname
);
printf("Not connected.\n");
printf("Connected for proxy commands to %s.\n", hostname
);
printf("No proxy connection.\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("Store unique: %s; Receive unique: %s\n", onoff(sunique
),
printf("Case: %s; CR stripping: %s\n",onoff(mcase
),onoff(crflag
));
printf("Ntrans: (in) %s (out) %s\n", ntin
,ntout
);
printf("Nmap: (in) %s (out) %s\n", mapin
, mapout
);
printf("Hash mark printing: %s; Use of PORT cmds: %s\n",
onoff(hash
), onoff(sendport
));
for (i
=0; i
<macnum
; i
++) {
printf("\t%s\n",macros
[i
].mac_name
);
* 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)", 1024);
* 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
if (argc
< 2 && !another(&argc
, &argv
, "remote-directory")) {
printf("usage: %s remote-directory\n", argv
[0]);
if (command("CWD %s", argv
[1]) == ERROR
&& code
== 500) {
printf("CWD command not recognized, trying XCWD\n");
(void) command("XCWD %s", argv
[1]);
* Set current working directory
printf("usage: %s local-directory\n", argv
[0]);
if (!globulize(&argv
[1])) {
if (chdir(argv
[1]) < 0) {
warn("local: %s", argv
[1]);
printf("Local directory now %s\n", buf
);
if (argc
< 2 && !another(&argc
, &argv
, "remote-file")) {
printf("usage: %s remote-file\n", argv
[0]);
(void) command("DELE %s", argv
[1]);
if (argc
< 2 && !another(&argc
, &argv
, "remote-files")) {
printf("usage: %s remote-files\n", argv
[0]);
oldintr
= signal(SIGINT
, mabort
);
while ((cp
= remglob(argv
,0)) != NULL
) {
if (mflag
&& confirm(argv
[0], cp
)) {
(void) command("DELE %s", cp
);
if (!mflag
&& fromatty
) {
if (confirm("Continue with", "mdelete")) {
(void) signal(SIGINT
, oldintr
);
if (argc
< 2 && !another(&argc
, &argv
, "from-name"))
if (argc
< 3 && !another(&argc
, &argv
, "to-name")) {
printf("%s from-name to-name\n", argv
[0]);
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] == 'n' ? "NLST" : "LIST";
if (strcmp(argv
[2], "-") && !globulize(&argv
[2])) {
if (strcmp(argv
[2], "-") && *argv
[2] != '|')
if (!globulize(&argv
[2]) || !confirm("output to local-file:", argv
[2])) {
recvrequest(cmd
, argv
[2], argv
[1], "w", 0);
* Get a directory listing
* of multiple remote files.
char *cmd
, mode
[1], *dest
;
if (argc
< 2 && !another(&argc
, &argv
, "remote-files"))
if (argc
< 3 && !another(&argc
, &argv
, "local-file")) {
printf("usage: %s remote-files local-file\n", argv
[0]);
if (strcmp(dest
, "-") && *dest
!= '|')
!confirm("output to local-file:", dest
)) {
cmd
= argv
[0][1] == 'l' ? "NLST" : "LIST";
oldintr
= signal(SIGINT
, mabort
);
for (i
= 1; mflag
&& i
< argc
-1; ++i
) {
*mode
= (i
== 1) ? 'w' : 'a';
recvrequest(cmd
, dest
, argv
[i
], mode
, 0);
if (!mflag
&& fromatty
) {
if (confirm("Continue with", argv
[0])) {
(void) signal(SIGINT
, oldintr
);
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
++)
(void) signal(SIGINT
, SIG_DFL
);
(void) signal(SIGQUIT
, SIG_DFL
);
namep
= strrchr(shell
,'/');
(void) strcpy(shellnam
,"-");
(void) strcat(shellnam
, ++namep
);
if (strcmp(namep
, "sh") != 0)
execl(shell
,shellnam
,"-c",altarg
,(char *)0);
execl(shell
,shellnam
,(char *)0);
while (wait((int *)&status
) != pid
)
(void) signal(SIGINT
, old1
);
(void) signal(SIGQUIT
, old2
);
warn("%s", "Try again later");
* Send new user information (re-login)
(void) another(&argc
, &argv
, "username");
if (argc
< 2 || argc
> 4) {
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", argv
[3]);
fprintf(stdout
, "Login failed.\n");
if (!aflag
&& argc
== 4) {
(void) command("ACCT %s", argv
[3]);
* Print working directory.
int oldverbose
= verbose
;
* If we aren't verbose, this doesn't do anything!
if (command("PWD") == ERROR
&& code
== 500) {
printf("PWD command not recognized, trying XPWD\n");
if (argc
< 2 && !another(&argc
, &argv
, "directory-name")) {
printf("usage: %s directory-name\n", argv
[0]);
if (command("MKD %s", argv
[1]) == ERROR
&& code
== 500) {
printf("MKD command not recognized, trying XMKD\n");
(void) command("XMKD %s", argv
[1]);
if (argc
< 2 && !another(&argc
, &argv
, "directory-name")) {
printf("usage: %s directory-name\n", argv
[0]);
if (command("RMD %s", argv
[1]) == ERROR
&& code
== 500) {
printf("RMD command not recognized, trying XRMD\n");
(void) command("XRMD %s", argv
[1]);
* Send a line, verbatim, to the remote machine.
if (argc
< 2 && !another(&argc
, &argv
, "command line to send")) {
printf("usage: %s line-to-send\n", argv
[0]);
* Send a SITE command to the remote machine. The line
* is sent verbatim to the remote machine, except that the
* word "SITE" is added at the front.
if (argc
< 2 && !another(&argc
, &argv
, "arguments to SITE command")) {
printf("usage: %s line-to-send\n", argv
[0]);
quote1("SITE ", argc
, argv
);
* Turn argv[1..argc) into a space-separated string, then prepend initial text.
* Send the result as a one-line command and get response.
quote1(initial
, argc
, argv
)
char buf
[BUFSIZ
]; /* must be >= sizeof(line) */
(void) strcpy(buf
, initial
);
len
+= strlen(strcpy(&buf
[len
], argv
[1]));
for (i
= 2; i
< argc
; i
++) {
len
+= strlen(strcpy(&buf
[len
], argv
[i
]));
if (command(buf
) == PRELIM
) {
while (getreply(0) == PRELIM
)
if (argc
< 2 && !another(&argc
, &argv
, "mode"))
if (argc
< 3 && !another(&argc
, &argv
, "file-name")) {
printf("usage: %s mode file-name\n", argv
[0]);
(void) command("SITE CHMOD %s %s", argv
[1], argv
[2]);
int oldverbose
= verbose
;
(void) command(argc
== 1 ? "SITE UMASK" : "SITE UMASK %s", argv
[1]);
int oldverbose
= verbose
;
(void) command(argc
== 1 ? "SITE IDLE" : "SITE IDLE %s", argv
[1]);
* 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
);
if (fgets(line
, sizeof line
, stdin
) == NULL
)
return (*line
!= 'n' && *line
!= '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.
flags
= GLOB_BRACE
|GLOB_NOCHECK
|GLOB_QUOTE
|GLOB_TILDE
;
memset(&gl
, 0, sizeof(gl
));
if (glob(*cpp
, flags
, NULL
, &gl
) ||
warnx("%s: not found", *cpp
);
*cpp
= strdup(gl
.gl_pathv
[0]); /* XXX - wasted memory */
(void) strncpy(acct
,*argv
,49);
(void) strncat(acct
,*argv
, 49-strlen(acct
));
ap
= getpass("Account:");
(void) command("ACCT %s", ap
);
if (argc
< 2 && !another(&argc
, &argv
, "command")) {
printf("usage: %s command\n", argv
[0]);
if (c
== (struct cmd
*) -1) {
printf("?Ambiguous command\n");
printf("?Invalid command\n");
printf("?Invalid proxy command\n");
oldintr
= signal(SIGINT
, proxabort
);
if (c
->c_conn
&& !connected
) {
printf("Not connected\n");
(void) signal(SIGINT
, oldintr
);
(*c
->c_handler
)(argc
-1, argv
+1);
(void) signal(SIGINT
, oldintr
);
printf("Case mapping %s.\n", onoff(mcase
));
printf("Carriage Return stripping %s.\n", onoff(crflag
));
(void) strncpy(ntin
, argv
[1], 16);
(void) strncpy(ntout
, argv
[2], 16);
static char new[MAXPATHLEN
];
for (ostop
= 0; *(ntout
+ ostop
) && ostop
< 16; ostop
++)
for (cp1
= name
; *cp1
; cp1
++) {
for (i
= 0; *(ntin
+ i
) && i
< 16; i
++) {
if (*cp1
== *(ntin
+ i
)) {
if (argc
< 3 && !another(&argc
, &argv
, "mapout")) {
printf("Usage: %s [mapin mapout]\n",argv
[0]);
cp
= strchr(altarg
, ' ');
cp
= strchr(altarg
, ' ');
(void) strncpy(mapin
, altarg
, MAXPATHLEN
- 1);
(void) strncpy(mapout
, cp
, MAXPATHLEN
- 1);
static char new[MAXPATHLEN
];
char *cp1
= name
, *cp2
= mapin
;
int i
, toks
[9], toknum
= 0, match
= 1;
while (match
&& *cp1
&& *cp2
) {
if (*(cp2
+1) >= '1' && (*cp2
+1) <= '9') {
if (*cp1
!= *(++cp2
+1)) {
toks
[toknum
= *cp2
- '1']++;
while (*++cp1
&& *(cp2
+1)
if (!match
&& *cp1
) /* last token mismatch */
if (*++cp2
== '$' && isdigit(*(cp2
+1))) {
else if (toks
[toknum
= *cp2
- '1']) {
while (cp3
!= te
[toknum
]) {
while (*cp2
&& *cp2
!= ',' &&
printf("nmap: unbalanced brackets\n");
while (*++cp2
&& *cp2
!= ']') {
if (*cp2
== '\\' && *(cp2
+ 1)) {
printf("nmap: unbalanced brackets\n");
if (isdigit(*(cp2
+ 1))) {
else if (toks
[toknum
= *cp2
- '1']) {
while (cp3
!= te
[toknum
]) {
/* intentional drop through */
passivemode
= !passivemode
;
printf("Passive mode %s.\n", onoff(passivemode
));
printf("Store unique %s.\n", onoff(sunique
));
printf("Receive unique %s.\n", onoff(runique
));
/* change directory to perent directory */
if (command("CDUP") == ERROR
&& code
== 500) {
printf("CDUP command not recognized, trying XCUP\n");
/* restart transfer at specific point */
printf("restart: offset not specified\n");
restart_point
= atol(argv
[1]);
printf("restarting at %qd. %s\n", restart_point
,
"execute get, put or append to initiate transfer");
/* show remote system type */
printf("Limit of 16 macros have already been defined\n");
if (argc
< 2 && !another(&argc
, &argv
, "macro name")) {
printf("Usage: %s macro_name\n",argv
[0]);
printf("Enter macro line by line, terminating it with a null line\n");
(void) strncpy(macros
[macnum
].mac_name
, argv
[1], 8);
macros
[macnum
].mac_start
= macbuf
;
macros
[macnum
].mac_start
= macros
[macnum
- 1].mac_end
+ 1;
tmp
= macros
[macnum
].mac_start
;
while (tmp
!= macbuf
+4096) {
if ((c
= getchar()) == EOF
) {
printf("macdef:end of file encountered\n");
if ((*tmp
= c
) == '\n') {
if (tmp
== macros
[macnum
].mac_start
) {
macros
[macnum
++].mac_end
= tmp
;
macros
[macnum
++].mac_end
= tmp
- 1;
while ((c
= getchar()) != '\n' && c
!= EOF
)
if (c
== EOF
|| getchar() == '\n') {
printf("Macro not defined - 4k buffer exceeded\n");
* get size of file on remote machine
if (argc
< 2 && !another(&argc
, &argv
, "filename")) {
printf("usage: %s filename\n", argv
[0]);
(void) command("SIZE %s", argv
[1]);
* get last modification time of file on remote machine
if (argc
< 2 && !another(&argc
, &argv
, "filename")) {
printf("usage: %s filename\n", argv
[0]);
if (command("MDTM %s", argv
[1]) == COMPLETE
) {
int yy
, mo
, day
, hour
, min
, sec
;
sscanf(reply_string
, "%*s %04d%02d%02d%02d%02d%02d", &yy
, &mo
,
&day
, &hour
, &min
, &sec
);
/* might want to print this in local time */
printf("%s\t%02d/%02d/%04d %02d:%02d:%02d GMT\n", argv
[1],
mo
, day
, yy
, hour
, min
, sec
);
printf("%s\n", reply_string
);
* show status on reomte machine
(void) command(argc
> 1 ? "STAT %s" : "STAT" , argv
[1]);
* get file if modtime is more recent than current file
if (getit(argc
, argv
, -1, "w"))
printf("Local file \"%s\" is newer than remote file \"%s\"\n",