summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authormichaels <michaels@cvs.openbsd.org>1996-12-17 02:11:47 +0000
committermichaels <michaels@cvs.openbsd.org>1996-12-17 02:11:47 +0000
commitc5dcb0430c6899e78fbba6239a0ba2ca78d15c91 (patch)
tree8315476583385106d506515900b4f72c14404ef1 /usr.bin
parent5a09a67a00e664c638ec75e42527b7be43e106e9 (diff)
if pathname given is a valid directory, cd to it at remote, also
assume empty pathname means cd to '/', like ncftp (?).
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ftp/cmds.c20
-rw-r--r--usr.bin/ftp/extern.h4
-rw-r--r--usr.bin/ftp/main.c28
3 files changed, 37 insertions, 15 deletions
diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c
index 795ae55919d..a2ec1907f57 100644
--- a/usr.bin/ftp/cmds.c
+++ b/usr.bin/ftp/cmds.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmds.c,v 1.6 1996/11/09 19:53:59 kstailey Exp $ */
+/* $OpenBSD: cmds.c,v 1.7 1996/12/17 02:11:46 michaels Exp $ */
/* $NetBSD: cmds.c,v 1.8 1995/09/08 01:06:05 tls Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else
-static char rcsid[] = "$OpenBSD: cmds.c,v 1.6 1996/11/09 19:53:59 kstailey Exp $";
+static char rcsid[] = "$OpenBSD: cmds.c,v 1.7 1996/12/17 02:11:46 michaels Exp $";
#endif
#endif /* not lint */
@@ -1079,7 +1079,7 @@ setdebug(argc, argv)
* Set current working directory
* on remote machine.
*/
-void
+int
cd(argc, argv)
int argc;
char *argv[];
@@ -1090,11 +1090,17 @@ cd(argc, argv)
code = -1;
return;
}
- if (command("CWD %s", argv[1]) == ERROR && code == 500) {
- if (verbose)
- printf("CWD command not recognized, trying XCWD\n");
- (void) command("XCWD %s", argv[1]);
+ if (command("CWD %s", argv[1]) == ERROR) {
+ if (code == 500) {
+ if (verbose)
+ printf("CWD command not recognized, "
+ "trying XCWD\n");
+ return(command("XCWD %s", argv[1]));
+ }
+ else
+ return(-1);
}
+ return(0);
}
/*
diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h
index 8b6eda3e1ef..5510736df21 100644
--- a/usr.bin/ftp/extern.h
+++ b/usr.bin/ftp/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.3 1996/09/03 18:00:05 deraadt Exp $ */
+/* $OpenBSD: extern.h,v 1.4 1996/12/17 02:11:46 michaels Exp $ */
/* $NetBSD: extern.h,v 1.4 1995/09/08 01:06:19 tls Exp $ */
/*-
@@ -46,7 +46,7 @@ void abortsend __P(());
void account __P((int, char **));
int another __P((int *, char ***, char *));
void blkfree __P((char **));
-void cd __P((int, char **));
+int cd __P((int, char **));
void cdup __P((int, char **));
void changetype __P((int, int));
void cmdabort __P(());
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c
index 394dfc82ca0..a9bf56de0db 100644
--- a/usr.bin/ftp/main.c
+++ b/usr.bin/ftp/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.8 1996/11/09 19:58:59 kstailey Exp $ */
+/* $OpenBSD: main.c,v 1.9 1996/12/17 02:11:45 michaels Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.8 1996/11/09 19:58:59 kstailey Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.9 1996/12/17 02:11:45 michaels Exp $";
#endif
#endif /* not lint */
@@ -163,6 +163,7 @@ main(argc, argv)
home = homedir;
(void) strcpy(home, pw->pw_dir);
}
+
if (argc > 0 && strchr(argv[0], ':')) {
int ret = 0;
anonftp = 1;
@@ -172,7 +173,7 @@ main(argc, argv)
extern char *__progname;
char portstr[20], *p, *bufp = NULL;
char *host = NULL, *dir = NULL, *file = NULL;
- int xargc = 2;
+ int xargc = 2, tmp;
if (setjmp(toplevel))
exit(0);
@@ -220,14 +221,28 @@ main(argc, argv)
goto bail;
}
- setbinary(NULL, 0);
-
- if (dir) {
+ if (dir != NULL && *dir != '\0') {
xargv[1] = dir;
xargv[2] = NULL;
xargc = 2;
cd(xargc, xargv);
}
+ /*
+ * either "file" is the file user wants, or he wants
+ * to cd to "file" aswell, so try cd first, after
+ * switcing of verbose (already got a CWD from above).
+ */
+ xargv[1] = *file == '\0' ? "/" : file;
+ xargv[2] = NULL;
+ xargc = 2;
+ tmp = verbose;
+ verbose = 0;
+ if (cd(xargc, xargv) == 0) {
+ verbose = tmp;
+ goto CLINE_CD;
+ }
+ verbose = tmp;
+ setbinary(NULL, 0);
/* fetch file */
xargv[1] = file;
@@ -272,6 +287,7 @@ bail:
}
} while (!connected);
}
+CLINE_CD:
top = setjmp(toplevel) == 0;
if (top) {
(void) signal(SIGINT, intr);