Re: < ftp-problem with windows-nt ftpserver >

From: <carson@dont-contact.us>
Date: Fri, 2 Aug 1996 16:10:05 -0400

Well, as long as it's an internet-draft... :)

Here's my take on the combined ftpget.c patches. I fix both DOS and EPLF
parsing (although my DOS patch isn't quite as anal in it's parsing as one of
the previous ones), and also fix a bug in the PASV code (found visiting
ftp://koobera.math.uic.edu/ as well :).

This has only been very lightly tested, so use at your own risk.

*** ftpget.c.orig Thu Aug 1 11:35:16 1996
--- ftpget.c Fri Aug 2 16:08:51 1996
***************
*** 1531,1537 ****
          return PASV_FAIL;
      }
      /* 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2). */
! n = sscanf(server_reply_msg + 3, "%[^0-9]%d,%d,%d,%d,%d,%d",
          junk, &h1, &h2, &h3, &h4, &p1, &p2);
      if (n != 7) {
          r->errmsg = xstrdup(server_reply_msg);
--- 1531,1537 ----
          return PASV_FAIL;
      }
      /* 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2). */
! n = sscanf(server_reply_msg, "%[^0-9]%d,%d,%d,%d,%d,%d",
          junk, &h1, &h2, &h3, &h4, &p1, &p2);
      if (n != 7) {
          r->errmsg = xstrdup(server_reply_msg);
***************
*** 1818,1837 ****
  
      /* try it as a DOS listing */
      if (n_tokens > 3 && p->name == NULL &&
! !sscanf(tokens[0], "%[-0-9]", sbuf) && /* 04-05-70 */
! !sscanf(tokens[1], "%[0-9:apm]", sbuf)) { /* 09:33pm */
          if (!strcasecmp(tokens[2], "<dir>")) {
              p->type = 'd';
- sprintf(sbuf, "%s %s", tokens[0], tokens[1]);
- p->date = xstrdup(sbuf);
- p->name = xstrdup(tokens[3]);
          }
! p->type = '-';
          sprintf(sbuf, "%s %s", tokens[0], tokens[1]);
          p->date = xstrdup(sbuf);
- p->size = atoi(tokens[2]);
          p->name = xstrdup(tokens[3]);
      }
      for (i = 0; i < n_tokens; i++)
          xfree(tokens[i]);
      if (p->name == NULL) {
--- 1818,1873 ----
  
      /* try it as a DOS listing */
      if (n_tokens > 3 && p->name == NULL &&
! sscanf(tokens[0], "%[-0-9]", sbuf) && /* 04-05-70 */
! sscanf(tokens[1], "%[0-9:apm]", sbuf)) { /* 09:33pm */
          if (!strcasecmp(tokens[2], "<dir>")) {
              p->type = 'd';
          }
! else {
! p->type = '-';
! p->size = atoi(tokens[2]);
! }
          sprintf(sbuf, "%s %s", tokens[0], tokens[1]);
          p->date = xstrdup(sbuf);
          p->name = xstrdup(tokens[3]);
      }
+
+ /* Try EPLF format */
+ if (p->name == NULL &&
+ buf[0] == '+') {
+ t = buf + 1;
+ p->type = 0;
+ while (t && *t) {
+ switch (*t) {
+ case '\t':
+ sscanf(t+1,"%[^,]",sbuf);
+ p->name = xstrdup(sbuf);
+ break;
+ case 's':
+ sscanf(t+1,"%d",&(p->size));
+ break;
+ case 'm':
+ sscanf(t+1,"%d",&i);
+ p->date = xstrdup(ctime((time_t *)&i));
+ *(strstr(p->date,"\n")) = '\0';
+ break;
+ case '/':
+ p->type = 'd';
+ break;
+ case 'r':
+ p->type = '-';
+ break;
+ case 'i':
+ break;
+ default:
+ break;
+ }
+ t = strstr(t,",");
+ if (t) { t++; }
+ }
+ if (p->type == 0) { p->type = '-'; }
+ }
+
      for (i = 0; i < n_tokens; i++)
          xfree(tokens[i]);
      if (p->name == NULL) {
***************
*** 1839,1844 ****
--- 1875,1881 ----
          xfree(p);
          p = NULL;
      }
+
      return p;
  }

--
Carson Gaspar -- carson@cs.columbia.edu carson@lehman.com
http://www.cs.columbia.edu/~carson/home.html
<This is the boring business .sig - no outre sayings here>
Received on Fri Aug 02 1996 - 13:15:11 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:32:45 MST