[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.74 and 1.75

version 1.74, 2007/06/13 13:52:26 version 1.75, 2007/11/26 12:39:00
Line 184 
Line 184 
         else          else
                 savefile = basename(path);                  savefile = basename(path);
   
   #ifndef SMALL
           if (resume && (strcmp(savefile, "-") == 0)) {
                   warnx("can't append to stdout");
                   goto cleanup_url_get;
           }
   #endif
   
         if (EMPTYSTRING(savefile)) {          if (EMPTYSTRING(savefile)) {
                 if (isftpurl)                  if (isftpurl)
                         goto noftpautologin;                          goto noftpautologin;
Line 259 
Line 266 
   
                 /* Open the output file.  */                  /* Open the output file.  */
                 if (strcmp(savefile, "-") != 0) {                  if (strcmp(savefile, "-") != 0) {
                         out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC,  #ifndef SMALL
                             0666);                          if (resume)
                                   out = open(savefile, O_APPEND | O_WRONLY);
                           else
   #endif
                                   out = open(savefile, O_CREAT | O_WRONLY |
                                           O_TRUNC, 0666);
                         if (out < 0) {                          if (out < 0) {
                                 warn("Can't open %s", savefile);                                  warn("Can't open %s", savefile);
                                 goto cleanup_url_get;                                  goto cleanup_url_get;
Line 268 
Line 280 
                 } else                  } else
                         out = fileno(stdout);                          out = fileno(stdout);
   
   #ifndef SMALL
                   if (resume) {
                           if (fstat(out, &st) == -1) {
                                   warn("Can't fstat %s", savefile);
                                   goto cleanup_url_get;
                           }
                           if (lseek(s, st.st_size, SEEK_SET) == -1) {
                                   warn("Can't lseek %s", path);
                                   goto cleanup_url_get;
                           }
                           restart_point = st.st_size;
                   }
   #endif
   
                 /* Trap signals */                  /* Trap signals */
                 oldintr = NULL;                  oldintr = NULL;
                 if (setjmp(httpabort)) {                  if (setjmp(httpabort)) {
Line 467 
Line 493 
                             path, buf ? buf : "", HTTP_USER_AGENT);                              path, buf ? buf : "", HTTP_USER_AGENT);
   
         } else {          } else {
                 ftp_printf(fin, ssl, "GET /%s HTTP/1.0\r\nHost: ", path);                  ftp_printf(fin, ssl, "GET /%s %s\r\nHost: ", path,
   #ifndef SMALL
                           resume ? "HTTP/1.1" :
   #endif
                           "HTTP/1.0");
                 if (strchr(host, ':')) {                  if (strchr(host, ':')) {
                         char *h, *p;                          char *h, *p;
   
Line 493 
Line 523 
 #ifndef SMALL  #ifndef SMALL
                 if (port && strcmp(port, (ishttpsurl ? "443" : "80")) != 0)                  if (port && strcmp(port, (ishttpsurl ? "443" : "80")) != 0)
                         ftp_printf(fin, ssl, ":%s", port);                          ftp_printf(fin, ssl, ":%s", port);
                   if (resume) {
                           int ret;
                           struct stat stbuf;
   
                           ret = stat(savefile, &stbuf);
                           if (ret < 0) {
                                   if (verbose)
                                           fprintf(ttyout, "\n");
                                   warn("Can't open %s", savefile);
                                   goto cleanup_url_get;
                           }
                           restart_point = stbuf.st_size;
                           ftp_printf(fin, ssl, "\r\nRange: bytes=%lld-",
                                   (long long)restart_point);
                   }
 #else  #else
                 if (port && strcmp(port, "80") != 0)                  if (port && strcmp(port, "80") != 0)
                         ftp_printf(fin, ssl, ":%s", port);                          ftp_printf(fin, ssl, ":%s", port);
Line 530 
Line 575 
                 cp++;                  cp++;
   
         strlcpy(ststr, cp, sizeof(ststr));          strlcpy(ststr, cp, sizeof(ststr));
         status = strtonum(ststr, 200, 307, &errstr);          status = strtonum(ststr, 200, 416, &errstr);
         if (errstr) {          if (errstr) {
                 warnx("Error retrieving file: %s", cp);                  warnx("Error retrieving file: %s", cp);
                 goto cleanup_url_get;                  goto cleanup_url_get;
Line 538 
Line 583 
   
         switch (status) {          switch (status) {
         case 200:       /* OK */          case 200:       /* OK */
   #ifndef SMALL
           case 206:       /* Partial Content */
                 break;                  break;
   #endif
         case 301:       /* Moved Permanently */          case 301:       /* Moved Permanently */
         case 302:       /* Found */          case 302:       /* Found */
         case 303:       /* See Other */          case 303:       /* See Other */
Line 549 
Line 597 
                         goto cleanup_url_get;                          goto cleanup_url_get;
                 }                  }
                 break;                  break;
   #ifndef SMALL
           case 416:       /* Requested Range Not Satisfiable */
                   warnx("File is already fully retrieved.");
                   goto cleanup_url_get;
   #endif
         default:          default:
                 warnx("Error retrieving file: %s", cp);                  warnx("Error retrieving file: %s", cp);
                 goto cleanup_url_get;                  goto cleanup_url_get;
Line 581 
Line 634 
                         filesize = strtonum(cp, 0, LLONG_MAX, &errstr);                          filesize = strtonum(cp, 0, LLONG_MAX, &errstr);
                         if (errstr != NULL)                          if (errstr != NULL)
                                 goto improper;                                  goto improper;
   #ifndef SMALL
                           if (resume)
                                   filesize += restart_point;
   #endif
 #define LOCATION "Location: "  #define LOCATION "Location: "
                 } else if (isredirect &&                  } else if (isredirect &&
                     strncasecmp(cp, LOCATION, sizeof(LOCATION) - 1) == 0) {                      strncasecmp(cp, LOCATION, sizeof(LOCATION) - 1) == 0) {
Line 601 
Line 658 
   
         /* Open the output file.  */          /* Open the output file.  */
         if (strcmp(savefile, "-") != 0) {          if (strcmp(savefile, "-") != 0) {
                 out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666);  #ifndef SMALL
                   if (resume)
                           out = open(savefile, O_APPEND | O_WRONLY);
                   else
   #endif
                           out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC,
                                   0666);
                 if (out < 0) {                  if (out < 0) {
                         warn("Can't open %s", savefile);                          warn("Can't open %s", savefile);
                         goto cleanup_url_get;                          goto cleanup_url_get;
Line 659 
Line 722 
                 goto cleanup_url_get;                  goto cleanup_url_get;
         }          }
         progressmeter(1);          progressmeter(1);
         if (filesize != -1 && len == 0 && bytes != filesize) {          if (
   #ifndef SMALL
                   !resume &&
   #endif
                   filesize != -1 && len == 0 && bytes != filesize) {
                 if (verbose)                  if (verbose)
                         fputs("Read short file.\n", ttyout);                          fputs("Read short file.\n", ttyout);
                 goto cleanup_url_get;                  goto cleanup_url_get;
Line 1002 
Line 1069 
                                 xargv[3] = NULL;                                  xargv[3] = NULL;
                                 xargc++;                                  xargc++;
                         }                          }
                         get(xargc, xargv);  #ifndef SMALL
                           if (resume)
                                   reget(xargc, xargv);
                           else
   #endif
                                   get(xargc, xargv);
                 }                  }
   
                 if ((code / 100) != COMPLETE)                  if ((code / 100) != COMPLETE)

Legend:
Removed from v.1.74  
changed lines
  Added in v.1.75