date and time created 88/12/14 15:30:10 by sklower
[unix-history] / usr / src / usr.bin / ftp / ftp.c
index 2ae46e7..d50edea 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ftp.c      5.19 (Berkeley) %G%";
+static char sccsid[] = "@(#)ftp.c      5.22 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ftp_var.h"
 #endif /* not lint */
 
 #include "ftp_var.h"
@@ -68,7 +68,8 @@ hookup(host, port)
        else {
                hp = gethostbyname(host);
                if (hp == NULL) {
        else {
                hp = gethostbyname(host);
                if (hp == NULL) {
-                       printf("%s: unknown host\n", host);
+                       fprintf(stderr, "ftp: %s: ", host);
+                       herror((char *)NULL);
                        code = -1;
                        return((char *) 0);
                }
                        code = -1;
                        return((char *) 0);
                }
@@ -159,7 +160,7 @@ login(host)
        char *host;
 {
        char tmp[80];
        char *host;
 {
        char tmp[80];
-       char *user, *pass, *acct, *getlogin(), *mygetpass();
+       char *user, *pass, *acct, *getlogin(), *getpass();
        int n, aflag = 0;
 
        user = pass = acct = 0;
        int n, aflag = 0;
 
        user = pass = acct = 0;
@@ -188,12 +189,12 @@ login(host)
        n = command("USER %s", user);
        if (n == CONTINUE) {
                if (pass == NULL)
        n = command("USER %s", user);
        if (n == CONTINUE) {
                if (pass == NULL)
-                       pass = mygetpass("Password:");
+                       pass = getpass("Password:");
                n = command("PASS %s", pass);
        }
        if (n == CONTINUE) {
                aflag++;
                n = command("PASS %s", pass);
        }
        if (n == CONTINUE) {
                aflag++;
-               acct = mygetpass("Account:");
+               acct = getpass("Account:");
                n = command("ACCT %s", acct);
        }
        if (n != COMPLETE) {
                n = command("ACCT %s", acct);
        }
        if (n != COMPLETE) {
@@ -380,8 +381,8 @@ abortsend()
 sendrequest(cmd, local, remote)
        char *cmd, *local, *remote;
 {
 sendrequest(cmd, local, remote)
        char *cmd, *local, *remote;
 {
-       FILE *fin, *dout = 0, *mypopen();
-       int (*closefunc)(), mypclose(), fclose(), (*oldintr)(), (*oldintp)();
+       FILE *fin, *dout = 0, *popen();
+       int (*closefunc)(), pclose(), fclose(), (*oldintr)(), (*oldintp)();
        int abortsend();
        char buf[BUFSIZ];
        long bytes = 0, hashbytes = sizeof (buf);
        int abortsend();
        char buf[BUFSIZ];
        long bytes = 0, hashbytes = sizeof (buf);
@@ -416,7 +417,7 @@ sendrequest(cmd, local, remote)
                fin = stdin;
        else if (*local == '|') {
                oldintp = signal(SIGPIPE,SIG_IGN);
                fin = stdin;
        else if (*local == '|') {
                oldintp = signal(SIGPIPE,SIG_IGN);
-               fin = mypopen(local + 1, "r");
+               fin = popen(local + 1, "r");
                if (fin == NULL) {
                        perror(local + 1);
                        (void) signal(SIGINT, oldintr);
                if (fin == NULL) {
                        perror(local + 1);
                        (void) signal(SIGINT, oldintr);
@@ -424,7 +425,7 @@ sendrequest(cmd, local, remote)
                        code = -1;
                        return;
                }
                        code = -1;
                        return;
                }
-               closefunc = mypclose;
+               closefunc = pclose;
        } else {
                fin = fopen(local, "r");
                if (fin == NULL) {
        } else {
                fin = fopen(local, "r");
                if (fin == NULL) {
@@ -531,7 +532,7 @@ sendrequest(cmd, local, remote)
        (void) fclose(dout);
        (void) getreply(0);
        (void) signal(SIGINT, oldintr);
        (void) fclose(dout);
        (void) getreply(0);
        (void) signal(SIGINT, oldintr);
-       if (bytes > 0 && verbose)
+       if (bytes > 0)
                ptransfer("sent", bytes, &start, &stop, local, remote);
        return;
 abort:
                ptransfer("sent", bytes, &start, &stop, local, remote);
        return;
 abort:
@@ -553,7 +554,7 @@ abort:
        code = -1;
        if (closefunc != NULL && fin != NULL)
                (*closefunc)(fin);
        code = -1;
        if (closefunc != NULL && fin != NULL)
                (*closefunc)(fin);
-       if (bytes > 0 && verbose)
+       if (bytes > 0)
                ptransfer("sent", bytes, &start, &stop, local, remote);
 }
 
                ptransfer("sent", bytes, &start, &stop, local, remote);
 }
 
@@ -572,8 +573,8 @@ abortrecv()
 recvrequest(cmd, local, remote, mode)
        char *cmd, *local, *remote, *mode;
 {
 recvrequest(cmd, local, remote, mode)
        char *cmd, *local, *remote, *mode;
 {
-       FILE *fout, *din = 0, *mypopen();
-       int (*closefunc)(), mypclose(), fclose(), (*oldintr)(), (*oldintp)(); 
+       FILE *fout, *din = 0, *popen();
+       int (*closefunc)(), pclose(), fclose(), (*oldintr)(), (*oldintp)(); 
        int abortrecv(), oldverbose, oldtype = 0, tcrflag, nfnd;
        char buf[BUFSIZ], *gunique(), msg;
        long bytes = 0, hashbytes = sizeof (buf);
        int abortrecv(), oldverbose, oldtype = 0, tcrflag, nfnd;
        char buf[BUFSIZ], *gunique(), msg;
        long bytes = 0, hashbytes = sizeof (buf);
@@ -709,12 +710,12 @@ recvrequest(cmd, local, remote, mode)
                fout = stdout;
        else if (*local == '|') {
                oldintp = signal(SIGPIPE, SIG_IGN);
                fout = stdout;
        else if (*local == '|') {
                oldintp = signal(SIGPIPE, SIG_IGN);
-               fout = mypopen(local + 1, "w");
+               fout = popen(local + 1, "w");
                if (fout == NULL) {
                        perror(local+1);
                        goto abort;
                }
                if (fout == NULL) {
                        perror(local+1);
                        goto abort;
                }
-               closefunc = mypclose;
+               closefunc = pclose;
        }
        else {
                fout = fopen(local, mode);
        }
        else {
                fout = fopen(local, mode);
@@ -791,7 +792,7 @@ recvrequest(cmd, local, remote, mode)
        (void) gettimeofday(&stop, (struct timezone *)0);
        (void) fclose(din);
        (void) getreply(0);
        (void) gettimeofday(&stop, (struct timezone *)0);
        (void) fclose(din);
        (void) getreply(0);
-       if (bytes > 0 && verbose)
+       if (bytes > 0)
                ptransfer("received", bytes, &start, &stop, local, remote);
        if (oldtype) {
                if (!debug)
                ptransfer("received", bytes, &start, &stop, local, remote);
        if (oldtype) {
                if (!debug)
@@ -883,7 +884,7 @@ abort:
                (*closefunc)(fout);
        if (din)
                (void) fclose(din);
                (*closefunc)(fout);
        if (din)
                (void) fclose(din);
-       if (bytes > 0 && verbose)
+       if (bytes > 0)
                ptransfer("received", bytes, &start, &stop, local, remote);
        (void) signal(SIGINT,oldintr);
 }
                ptransfer("received", bytes, &start, &stop, local, remote);
        (void) signal(SIGINT,oldintr);
 }
@@ -984,16 +985,19 @@ ptransfer(direction, bytes, t0, t1, local, remote)
        struct timeval td;
        float s, bs;
 
        struct timeval td;
        float s, bs;
 
-       tvsub(&td, t1, t0);
-       s = td.tv_sec + (td.tv_usec / 1000000.);
+       if (verbose) {
+               tvsub(&td, t1, t0);
+               s = td.tv_sec + (td.tv_usec / 1000000.);
 #define        nz(x)   ((x) == 0 ? 1 : (x))
 #define        nz(x)   ((x) == 0 ? 1 : (x))
-       bs = bytes / nz(s);
-       if (local && *local != '-')
-               printf("local: %s ", local);
-       if (remote)
-               printf("remote: %s\n", remote);
-       printf("%ld bytes %s in %.2g seconds (%.2g Kbytes/s)\n",
-               bytes, direction, s, bs / 1024.);
+               bs = bytes / nz(s);
+               printf("%ld bytes %s in %.2g seconds (%.2g Kbytes/s)\n",
+                   bytes, direction, s, bs / 1024.);
+       } else {
+               if (local && *local != '-')
+                       printf("local: %s ", local);
+               if (remote)
+                       printf("remote: %s\n", remote);
+       }
 }
 
 /*tvadd(tsum, t0)
 }
 
 /*tvadd(tsum, t0)