[BACK]Return to fetch.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ftp

Diff for /src/usr.bin/ftp/fetch.c between version 1.9 and 1.10

version 1.9, 1997/04/18 18:56:49 version 1.10, 1997/04/23 20:33:06
Line 82 
Line 82 
  * Returns -1 on failure, 0 on success   * Returns -1 on failure, 0 on success
  */   */
 int  int
 url_get(line, proxyenv)  url_get(line, proxyenv, fd)
         char *line;          char *line;
         char *proxyenv;          char *proxyenv;
           int fd;
 {  {
         struct sockaddr_in sin;          struct sockaddr_in sin;
         int i, out, port, s;          int i, out, port, s;
Line 145 
Line 146 
                 *portnum++ = '\0';                  *portnum++ = '\0';
   
         if (debug)          if (debug)
                 printf("host %s, port %s, path %s, save as %s.\n",                  fprintf(ttyout, "host %s, port %s, path %s, save as %s.\n",
                     host, portnum, path, savefile);                      host, portnum, path, savefile);
   
         memset(&sin, 0, sizeof(sin));          memset(&sin, 0, sizeof(sin));
Line 198 
Line 199 
          * status of "200". Proxy requests don't want leading /.           * status of "200". Proxy requests don't want leading /.
          */           */
         if (!proxy)          if (!proxy)
                 printf("Requesting %s:%d/%s\n", line, ntohs(port), path);                  fprintf(ttyout, "Requesting %s:%d/%s\n", line, ntohs(port),
                       path);
         else          else
                 printf("Requesting %s (via %s)\n", line, proxyenv);                  fprintf(ttyout, "Requesting %s (via %s)\n", line, proxyenv);
         snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\n\n",          snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\n\n",
             proxy ? "" : "/", path);              proxy ? "" : "/", path);
         buflen = strlen(buf);          buflen = strlen(buf);
Line 264 
Line 266 
                 goto improper;                  goto improper;
   
         /* Open the output file. */          /* Open the output file. */
         out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666);          if (fd == -1) {
         if (out < 0) {                  out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666);
                 warn("Can't open %s", savefile);                  if (out < 0) {
                 goto cleanup_url_get;                          warn("Can't open %s", savefile);
         }                          goto cleanup_url_get;
                   }
           } else
                   out = fd;
   
         /* Trap signals */          /* Trap signals */
         oldintr = NULL;          oldintr = NULL;
Line 297 
Line 302 
                 }                  }
                 if (hash && !progress) {                  if (hash && !progress) {
                         while (bytes >= hashbytes) {                          while (bytes >= hashbytes) {
                                 (void)putchar('#');                                  (void)putc('#', ttyout);
                                 hashbytes += mark;                                  hashbytes += mark;
                         }                          }
                         (void)fflush(stdout);                          (void)fflush(ttyout);
                 }                  }
         }          }
         if (hash && !progress && bytes > 0) {          if (hash && !progress && bytes > 0) {
                 if (bytes < mark)                  if (bytes < mark)
                         (void)putchar('#');                          (void)putc('#', ttyout);
                 (void)putchar('\n');                  (void)putc('\n', ttyout);
                 (void)fflush(stdout);                  (void)fflush(ttyout);
         }          }
         if (len != 0) {          if (len != 0) {
                 warn("Reading from socket");                  warn("Reading from socket");
Line 315 
Line 320 
         }          }
         progressmeter(1);          progressmeter(1);
         if (verbose)          if (verbose)
                 puts("Successfully retrieved file.");                  fputs("Successfully retrieved file.\n", ttyout);
         (void)signal(SIGINT, oldintr);          (void)signal(SIGINT, oldintr);
   
         close(s);          close(s);
         close(out);          if (fd != -1)
                   close(out);
         if (proxy)          if (proxy)
                 free(proxy);                  free(proxy);
         return (0);          return (0);
Line 343 
Line 349 
 {  {
   
         alarmtimer(0);          alarmtimer(0);
         puts("\nhttp fetch aborted.");          fputs("\nhttp fetch aborted.\n", ttyout);
         (void)fflush(stdout);          (void)fflush(ttyout);
         longjmp(httpabort, 1);          longjmp(httpabort, 1);
 }  }
   
Line 363 
Line 369 
  * Otherwise, 0 is returned if all files retrieved successfully.   * Otherwise, 0 is returned if all files retrieved successfully.
  */   */
 int  int
 auto_fetch(argc, argv)  auto_fetch(argc, argv, fd)
         int argc;          int argc;
         char *argv[];          char *argv[];
           int fd;
 {  {
         static char lasthost[MAXHOSTNAMELEN];          static char lasthost[MAXHOSTNAMELEN];
         char *xargv[5];          char *xargv[5];
Line 374 
Line 381 
         char *ftpproxy, *httpproxy;          char *ftpproxy, *httpproxy;
         int rval, xargc, argpos;          int rval, xargc, argpos;
         int dirhasglob, filehasglob;          int dirhasglob, filehasglob;
         char rempath[MAXPATHLEN];          char rempath[MAXPATHLEN], fakedev[MAXPATHLEN];
   
         argpos = 0;          argpos = 0;
   
Line 408 
Line 415 
                  * Try HTTP URL-style arguments first.                   * Try HTTP URL-style arguments first.
                  */                   */
                 if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {                  if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {
                         if (url_get(line, httpproxy) == -1)                          if (url_get(line, httpproxy, fd) == -1)
                                 rval = argpos + 1;                                  rval = argpos + 1;
                         continue;                          continue;
                 }                  }
Line 421 
Line 428 
                 host = line;                  host = line;
                 if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) {                  if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
                         if (ftpproxy) {                          if (ftpproxy) {
                                 if (url_get(line, ftpproxy) == -1)                                  if (url_get(line, ftpproxy, fd) == -1)
                                         rval = argpos + 1;                                          rval = argpos + 1;
                                 continue;                                  continue;
                         }                          }
Line 487 
Line 494 
                         }                          }
                 }                  }
                 if (debug)                  if (debug)
                         printf("user %s:%s host %s port %s dir %s file %s\n",                          fprintf(ttyout, "user %s:%s host %s port %s dir %s file %s\n",
                             user, pass, host, portnum, dir, file);                              user, pass, host, portnum, dir, file);
   
                 /*                  /*
Line 562 
Line 569 
                 }                  }
   
                 if (!verbose)                  if (!verbose)
                         printf("Retrieving %s/%s\n", dir ? dir : "", file);                          fprintf(ttyout, "Retrieving %s/%s\n", dir ? dir : "", file);
   
                 if (dirhasglob) {                  if (dirhasglob) {
                         snprintf(rempath, sizeof(rempath), "%s/%s", dir, file);                          snprintf(rempath, sizeof(rempath), "%s/%s", dir, file);
Line 570 
Line 577 
                 }                  }
   
                 /* Fetch the file(s). */                  /* Fetch the file(s). */
                   xargc = 2;
                 xargv[0] = "get";                  xargv[0] = "get";
                 xargv[1] = file;                  xargv[1] = file;
                 xargv[2] = NULL;                  xargv[2] = NULL;
Line 579 
Line 587 
                         ointeractive = interactive;                          ointeractive = interactive;
                         interactive = 0;                          interactive = 0;
                         xargv[0] = "mget";                          xargv[0] = "mget";
                         mget(2, xargv);                          mget(xargc, xargv);
                         interactive = ointeractive;                          interactive = ointeractive;
                 } else                  } else {
                         get(2, xargv);                          if (fd != -1) {
                                   xargv[2] = "-";
                                   xargc++;
                           }
                           xargv[3] = NULL;
                           get(xargc, xargv);
                   }
   
                 if ((code / 100) != COMPLETE)                  if ((code / 100) != COMPLETE)
                         rval = argpos + 1;                          rval = argpos + 1;

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10