install with -s
[unix-history] / usr / src / usr.bin / ftp / cmds.c
index 3c30790..50cf1dc 100644 (file)
@@ -1,6 +1,12 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)cmds.c     4.6 (Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)cmds.c     5.1 (Berkeley) %G%";
+#endif not lint
 
 /*
  * FTP User Program -- Command Routines.
 
 /*
  * FTP User Program -- Command Routines.
@@ -14,7 +20,6 @@ static char sccsid[] = "@(#)cmds.c    4.6 (Berkeley) %G%";
 #include <stdio.h>
 #include <errno.h>
 #include <netdb.h>
 #include <stdio.h>
 #include <errno.h>
 #include <netdb.h>
-#include <stat.h>
 
 #include "ftp_var.h"
 
 
 #include "ftp_var.h"
 
@@ -200,6 +205,9 @@ setstruct(argc, argv)
        printf("We only support %s structure, sorry.\n", structname);
 }
 
        printf("We only support %s structure, sorry.\n", structname);
 }
 
+/*
+ * Send a single file.
+ */
 put(argc, argv)
        int argc;
        char *argv[];
 put(argc, argv)
        int argc;
        char *argv[];
@@ -243,7 +251,7 @@ usage:
 mput(argc, argv)
        char *argv[];
 {
 mput(argc, argv)
        char *argv[];
 {
-       char **cpp, **gargs = NULL;
+       register int i;
 
        if (argc < 2) {
                strcat(line, " ");
 
        if (argc < 2) {
                strcat(line, " ");
@@ -257,23 +265,27 @@ mput(argc, argv)
                printf("%s local-files\n", argv[0]);
                return;
        }
                printf("%s local-files\n", argv[0]);
                return;
        }
-       cpp = argv + 1;
-       if (doglob) {
-               gargs = glob(cpp);
+       for (i = 1; i < argc; i++) {
+               register char **cpp, **gargs;
+
+               if (!doglob) {
+                       if (confirm(argv[0], argv[i]))
+                               sendrequest("STOR", argv[i], argv[i]);
+                       continue;
+               }
+               gargs = glob(argv[i]);
                if (globerr != NULL) {
                        printf("%s\n", globerr);
                        if (gargs)
                                blkfree(gargs);
                if (globerr != NULL) {
                        printf("%s\n", globerr);
                        if (gargs)
                                blkfree(gargs);
-                       return;
+                       continue;
                }
                }
+               for (cpp = gargs; cpp && *cpp != NULL; cpp++)
+                       if (confirm(argv[0], *cpp))
+                               sendrequest("STOR", *cpp, *cpp);
+               if (gargs != NULL)
+                       blkfree(gargs);
        }
        }
-       if (gargs != NULL)
-               cpp = gargs;
-       for (; *cpp != NULL; cpp++)
-               if (confirm(argv[0], *cpp))
-                       sendrequest("STOR", *cpp, *cpp);
-       if (gargs != NULL)
-               blkfree(gargs);
 }
 
 /*
 }
 
 /*
@@ -346,7 +358,7 @@ remglob(argc, argv)
        static char buf[MAXPATHLEN];
        static FILE *ftemp = NULL;
        static char **args;
        static char buf[MAXPATHLEN];
        static FILE *ftemp = NULL;
        static char **args;
-       int oldverbose;
+       int oldverbose, oldhash;
        char *cp, *mode;
 
        if (!doglob) {
        char *cp, *mode;
 
        if (!doglob) {
@@ -360,9 +372,10 @@ remglob(argc, argv)
                strcpy(temp, "/tmp/ftpXXXXXX");
                mktemp(temp);
                oldverbose = verbose, verbose = 0;
                strcpy(temp, "/tmp/ftpXXXXXX");
                mktemp(temp);
                oldverbose = verbose, verbose = 0;
+               oldhash = hash, hash = 0;
                for (mode = "w"; *++argv != NULL; mode = "a")
                        recvrequest ("NLST", temp, *argv, mode);
                for (mode = "w"; *++argv != NULL; mode = "a")
                        recvrequest ("NLST", temp, *argv, mode);
-               verbose = oldverbose;
+               verbose = oldverbose; hash = oldhash;
                ftemp = fopen(temp, "r");
                unlink(temp);
                if (ftemp == NULL) {
                ftemp = fopen(temp, "r");
                unlink(temp);
                if (ftemp == NULL) {
@@ -673,20 +686,37 @@ ls(argc, argv)
 mls(argc, argv)
        char *argv[];
 {
 mls(argc, argv)
        char *argv[];
 {
-       char *cmd, *mode;
-       int i, dest;
+       char *cmd, *mode, *cp, *dest;
 
 
-       if (argc < 2)
-               argc++, argv[1] = NULL;
-       if (argc < 3)
-               argc++, argv[2] = "-";
-       dest = argc - 1;
-       cmd = argv[0][1] == 'l' ? "NLST" : "LIST";
-       if (strcmp(argv[dest], "-") != 0)
-               if (globulize(&argv[dest]) && confirm("local-file", argv[dest]))
+       if (argc < 2) {
+               strcat(line, " ");
+               printf("(remote-files) ");
+               gets(&line[strlen(line)]);
+               makeargv();
+               argc = margc;
+               argv = margv;
+       }
+       if (argc < 3) {
+               strcat(line, " ");
+               printf("(local-file) ");
+               gets(&line[strlen(line)]);
+               makeargv();
+               argc = margc;
+               argv = margv;
+       }
+       if (argc < 3) {
+               printf("%s remote-files local-file\n", argv[0]);
+               return;
+       }
+       dest = argv[argc - 1];
+       argv[argc - 1] = NULL;
+       if (strcmp(dest, "-"))
+               if (!globulize(&dest) || !confirm("local-file", dest))
                        return;
                        return;
-       for (i = 1, mode = "w"; i < dest; i++, mode = "a")
-               recvrequest(cmd, argv[dest], argv[i], mode);
+       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);
 }
 
 /*
 }
 
 /*
@@ -904,7 +934,8 @@ rmthelp(argc, argv)
 quit()
 {
 
 quit()
 {
 
-       disconnect();
+       if (connected)
+               disconnect();
        exit(0);
 }
 
        exit(0);
 }