fix m* cmds and add linger control
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 20 Jun 1983 14:08:33 +0000 (06:08 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 20 Jun 1983 14:08:33 +0000 (06:08 -0800)
SCCS-vsn: usr.bin/ftp/cmds.c 4.7
SCCS-vsn: usr.bin/ftp/cmdtab.c 4.6
SCCS-vsn: usr.bin/ftp/ftp.c 4.9
SCCS-vsn: usr.bin/ftp/ftp_var.h 4.5

usr/src/usr.bin/ftp/cmds.c
usr/src/usr.bin/ftp/cmdtab.c
usr/src/usr.bin/ftp/ftp.c
usr/src/usr.bin/ftp/ftp_var.h

index 3c30790..ece60a7 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)cmds.c     4.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmds.c     4.7 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -243,7 +243,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 +257,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 +350,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 +364,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) {
@@ -403,8 +408,8 @@ status(argc, argv)
        printf("Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s\n", 
                onoff(verbose), onoff(bell), onoff(interactive),
                onoff(doglob));
        printf("Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s\n", 
                onoff(verbose), onoff(bell), onoff(interactive),
                onoff(doglob));
-       printf("Hash mark printing: %s; Use of PORT cmds: %s\n",
-               onoff(hash), onoff(sendport));
+       printf("Hash mark printing: %s; Use of PORT cmds: %s; Linger: %s\n",
+               onoff(hash), onoff(sendport), onoff(linger));
 }
 
 /*
 }
 
 /*
@@ -515,6 +520,26 @@ setdebug(argc, argv)
        printf("Debugging %s (debug=%d).\n", onoff(debug), debug);
 }
 
        printf("Debugging %s (debug=%d).\n", onoff(debug), debug);
 }
 
+/*
+ * Set linger on data connections on/off.
+ */
+/*VARARGS*/
+setlinger(argc, argv)
+       char *argv[];
+{
+
+       if (argc == 1)
+               linger = !linger;
+       else
+               linger = atoi(argv[1]);
+       if (argc == 1 || linger == 0) {
+               printf("Linger on data connection close %s.\n", onoff(linger));
+               return;
+       }
+       printf("Will linger for %d seconds on close of data connections.\n",
+          linger);
+}
+
 /*
  * Set current working directory
  * on remote machine.
 /*
  * Set current working directory
  * on remote machine.
@@ -673,20 +698,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);
 }
 
 /*
 }
 
 /*
index 0e8492f..2d64b44 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)cmdtab.c   4.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmdtab.c   4.6 (Berkeley) %G%";
 #endif
 
 #include "ftp_var.h"
 #endif
 
 #include "ftp_var.h"
@@ -8,7 +8,7 @@ static char sccsid[] = "@(#)cmdtab.c    4.5 (Berkeley) %G%";
  * User FTP -- Command Tables.
  */
 int    setascii(), setbell(), setbinary(), setdebug(), setform();
  * User FTP -- Command Tables.
  */
 int    setascii(), setbell(), setbinary(), setdebug(), setform();
-int    setglob(), sethash(), setmode(), setpeer(), setport ();
+int    setglob(), sethash(), setlinger(), setmode(), setpeer(), setport();
 int    setprompt(), setstruct();
 int    settenex(), settrace(), settype(), setverbose();
 int    disconnect();
 int    setprompt(), setstruct();
 int    settenex(), settrace(), settype(), setverbose();
 int    disconnect();
@@ -33,6 +33,7 @@ char  globhelp[] =    "toggle metacharacter expansion of local file names";
 char   hashhelp[] =    "toggle printing `#' for each buffer transferred";
 char   helphelp[] =    "print local help information";
 char   lcdhelp[] =     "change local working directory";
 char   hashhelp[] =    "toggle printing `#' for each buffer transferred";
 char   helphelp[] =    "print local help information";
 char   lcdhelp[] =     "change local working directory";
+char   lingerhelp[] =  "wait for other side when closing data connections";
 char   lshelp[] =      "nlist contents of remote directory";
 char   mdeletehelp[] = "delete multiple files";
 char   mdirhelp[] =    "list contents of multiple remote directories";
 char   lshelp[] =      "nlist contents of remote directory";
 char   mdeletehelp[] = "delete multiple files";
 char   mdirhelp[] =    "list contents of multiple remote directories";
@@ -78,6 +79,7 @@ struct cmd cmdtab[] = {
        { "hash",       hashhelp,       0,      0,      sethash },
        { "help",       helphelp,       0,      0,      help },
        { "lcd",        lcdhelp,        0,      0,      lcd },
        { "hash",       hashhelp,       0,      0,      sethash },
        { "help",       helphelp,       0,      0,      help },
        { "lcd",        lcdhelp,        0,      0,      lcd },
+       { "linger",     lingerhelp,     0,      0,      setlinger },
        { "ls",         lshelp,         1,      1,      ls },
        { "mdelete",    mdeletehelp,    1,      1,      mdelete },
        { "mdir",       mdirhelp,       1,      1,      mls },
        { "ls",         lshelp,         1,      1,      ls },
        { "mdelete",    mdeletehelp,    1,      1,      mdelete },
        { "mdir",       mdirhelp,       1,      1,      mls },
index 364b49b..ae2b804 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)ftp.c      4.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)ftp.c      4.9 (Berkeley) %G%";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
@@ -272,7 +272,7 @@ sendrequest(cmd, local, remote)
                                fflush(stdout);
                        }
                }
                                fflush(stdout);
                        }
                }
-               if (hash) {
+               if (hash && bytes > 0) {
                        putchar('\n');
                        fflush(stdout);
                }
                        putchar('\n');
                        fflush(stdout);
                }
@@ -303,6 +303,8 @@ sendrequest(cmd, local, remote)
                        }
                }
                if (hash) {
                        }
                }
                if (hash) {
+                       if (bytes < hashbytes)
+                               putchar('#');
                        putchar('\n');
                        fflush(stdout);
                }
                        putchar('\n');
                        fflush(stdout);
                }
@@ -404,7 +406,7 @@ recvrequest(cmd, local, remote, mode)
                                fflush(stdout);
                        }
                }
                                fflush(stdout);
                        }
                }
-               if (hash) {
+               if (hash && bytes > 0) {
                        putchar('\n');
                        fflush(stdout);
                }
                        putchar('\n');
                        fflush(stdout);
                }
@@ -437,6 +439,8 @@ recvrequest(cmd, local, remote, mode)
                        bytes++;
                }
                if (hash) {
                        bytes++;
                }
                if (hash) {
+                       if (bytes < hashbytes)
+                               putchar('#');
                        putchar('\n');
                        fflush(stdout);
                }
                        putchar('\n');
                        fflush(stdout);
                }
@@ -543,6 +547,9 @@ dataconn(mode)
        }
        (void) close(data);
        data = s;
        }
        (void) close(data);
        data = s;
+       if (*mode == 'w' && linger)
+               (void) setsockopt(s, SOL_SOCKET, SO_LINGER, &linger,
+                   sizeof (linger));
        return (fdopen(data, mode));
 }
 
        return (fdopen(data, mode));
 }
 
index 0397e27..75425e4 100644 (file)
@@ -1,4 +1,4 @@
-/*     ftp_var.h       4.4     83/03/23        */
+/*     ftp_var.h       4.5     83/06/19        */
 
 /*
  * FTP global variables.
 
 /*
  * FTP global variables.
@@ -17,6 +17,7 @@ int   interactive;            /* interactively prompt on m* cmds */
 int    debug;                  /* debugging level */
 int    bell;                   /* ring bell on cmd completion */
 int    doglob;                 /* glob local file names */
 int    debug;                  /* debugging level */
 int    bell;                   /* ring bell on cmd completion */
 int    doglob;                 /* glob local file names */
+int    linger;                 /* linger on close of data connections */
 int    autologin;              /* establish user account on connection */
 
 char   typename[32];           /* name of file transfer type */
 int    autologin;              /* establish user account on connection */
 
 char   typename[32];           /* name of file transfer type */