if pathname given is a valid directory, cd to it at remote, also
authormichaels <michaels@openbsd.org>
Tue, 17 Dec 1996 02:11:45 +0000 (02:11 +0000)
committermichaels <michaels@openbsd.org>
Tue, 17 Dec 1996 02:11:45 +0000 (02:11 +0000)
assume empty pathname means cd to '/', like ncftp (?).

usr.bin/ftp/cmds.c
usr.bin/ftp/extern.h
usr.bin/ftp/main.c

index 795ae55..a2ec190 100644 (file)
@@ -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);
 }
 
 /*
index 8b6eda3..5510736 100644 (file)
@@ -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(());
index 394dfc8..a9bf56d 100644 (file)
@@ -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);