Hi Darshit,

I just had some time to create a quick patch, but now my customers rush in...

We need either access to the OS/9 ftp server or have to extend the FTP test 
server (or better: both).

Tim

On Wednesday 14 October 2015 10:34:47 Marcell Jarvas wrote:
> Hi,
> 
> Thanks for the quick reply!
> 
> I attached the debug output.
> 
> I hope it helps.
> 
> Regards,
> Marcell
> 
> On Wed, Oct 14, 2015 at 8:43 AM, Darshit Shah <[email protected]> wrote:
> > Can you please share the debug output provided by Wget in this case?
> > 
> > It does seem like the issue is exactly what Wget reports, the server
> > is returning a .listing file that Wget does not know how to interpret.
> > I'd like to see the debug output just in case there's something else.
> > 
> > However, since I don't have access to a OS9 machine, I can only try to
> > reverse engineer using the listing file you've provided.
> > 
> > On 13 October 2015 at 15:36, Marcell Jarvas <[email protected]>
> > 
> > wrote:
> > > Hi,
> > > 
> > > I'm trying to download a folder from a specific tool's ftp server.
> > > I'm getting back the "Unsupported listing type" message.
> > > Switching on the debug function, the device tells that its OS is: "OS-9
> > > Type: L8 Version: OS9-ftpd May 11 2007"
> > > I attached the .listing file.
> > > 
> > > What can be the problem?
> > > 
> > > Please help!
> > > 
> > > Regards,
> > > Marcell
> > 
> > --
> > Thanking You,
> > Darshit Shah
>From 531e8faaaccc684a95b1f69d10e0beba3c2efb40 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim=20R=C3=BChsen?= <[email protected]>
Date: Wed, 14 Oct 2015 15:49:16 +0200
Subject: [PATCH] Support OS/9 FTP listings

---
 src/ftp-basic.c   |  6 ++++
 src/ftp-ls.c      | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/ftp.c         |  5 +++
 src/ftp.h         |  1 +
 tests/Makefile.am |  1 +
 5 files changed, 110 insertions(+)

diff --git a/src/ftp-basic.c b/src/ftp-basic.c
index bcb7847..0ca25bc 100644
--- a/src/ftp-basic.c
+++ b/src/ftp-basic.c
@@ -1203,6 +1203,12 @@ ftp_syst (int csock, enum stype *server_type, enum ustype *unix_type)
     *server_type = ST_MACOS;
   else if (!c_strcasecmp (request, "OS/400"))
     *server_type = ST_OS400;
+  else if (!c_strcasecmp (request, "OS/9"))
+    {
+      /* 215 OS-9 Type: L8 Version: OS9-ftpd May 11 2007 */
+      *server_type = ST_OS9;
+      *unix_type = UST_TYPE_L8;
+    }
   else
     *server_type = ST_OTHER;
 
diff --git a/src/ftp-ls.c b/src/ftp-ls.c
index f8342e2..e9b1a9a 100644
--- a/src/ftp-ls.c
+++ b/src/ftp-ls.c
@@ -678,6 +678,101 @@ static void eat_carets( char *str)
 
 
 static struct fileinfo *
+ftp_parse_os9_ls (const char *file)
+{
+  FILE *fp;
+  size_t bufsize = 0;
+  char *line = NULL;
+  char stime[5], perm[17], fname[128];
+  int fsize, itime, year, month, mday;
+  struct tm timestruct;
+  struct fileinfo *dir = NULL, *l = NULL, cur; /* list creation */
+
+  fp = fopen (file, "r");
+  if (!fp)
+    {
+      logprintf (LOG_NOTQUIET, "%s: %s\n", file, strerror (errno));
+      return NULL;
+    }
+
+  /* Example output:
+                     Directory of . 09:24:34
+  Owner   Last modified    Attributes     Block  Bytecount Name
+--------- ------------- ---------------- ------- --------- ----
+  0.0     15/06/23 0404 -----ewr-ewr-ewr   1F78C    262148 AProg.Par
+  0.0     15/09/27 1657 -----ewr-ewr-ewr   1F737     42772 Ablauf.Par
+  0.0     15/09/27 1657 -----ewr-ewr-ewr   1EE28        96 Anlage.Par
+  0.0     13/04/25 0705 -----ewr-ewr-ewr   1EE23       460 ApexTLSConfig.txt
+  0.0     13/04/25 0705 -----ewr-ewr-ewr   1EE24       742 ApexTLSConnection.txt
+  0.0     15/06/23 0423 d----swr-swr-swr    DCD6       512 DEFAULTS
+  0.0     15/06/23 0404 -----ewr-ewr-ewr   1FEE3      2308 EABER.Dat
+
+   */
+  while (getline (&line, &bufsize, fp) >= 0)
+    {
+      if (sscanf (line, " %*s %2d/%2d%2d %4s %16s %*s %d %127[^\r\n]",
+                  &year, &month, &mday, stime, perm, &fsize, fname) >= 5)
+        {
+          if (*perm == 'd')
+            {
+              cur.type  = FT_DIRECTORY;
+              cur.perms = VMS_DEFAULT_PROT_DIR;
+              DEBUGP (("Directory\n"));
+            }
+          else
+            {
+              cur.type  = FT_PLAINFILE;
+              cur.perms = VMS_DEFAULT_PROT_FILE;
+              DEBUGP (("File\n"));
+            }
+
+          cur.size = fsize;
+          cur.name = xstrdup (fname);
+          DEBUGP (("Name: '%s'\n", cur.name));
+
+          /* OS/9 lacks symbolic links. */
+          cur.linkto = NULL;
+
+          /* Build the time-stamp (copy & paste from above) */
+          itime = atoi(stime);
+          timestruct.tm_sec = 0;
+          timestruct.tm_min = itime % 100;
+          timestruct.tm_hour = itime / 100;
+          timestruct.tm_mday = mday;
+          timestruct.tm_mon = month - 1;
+          timestruct.tm_year = year >= 70 ? year : year + 100;
+          timestruct.tm_wday = 0;
+          timestruct.tm_yday = 0;
+          timestruct.tm_isdst = -1;
+          cur.tstamp = mktime (&timestruct); /* store the time-stamp */
+          cur.ptype = TT_HOUR_MIN;
+
+          DEBUGP (("Timestamp: %ld\n", cur.tstamp));
+
+          /* Add the data for this item to the linked list, */
+          if (!dir)
+            {
+              l = dir = (struct fileinfo *) xmalloc (sizeof (struct fileinfo));
+              memcpy (l, &cur, sizeof (cur));
+              l->prev = l->next = NULL;
+            }
+          else
+            {
+              cur.prev = l;
+              l->next = (struct fileinfo *) xmalloc (sizeof (struct fileinfo));
+              l = l->next;
+              memcpy (l, &cur, sizeof (cur));
+              l->next = NULL;
+            }
+        }
+    }
+
+  xfree (line);
+  fclose(fp);
+  return dir;
+}
+
+static struct fileinfo *
 ftp_parse_vms_ls (const char *file)
 {
   FILE *fp;
@@ -1046,6 +1141,8 @@ ftp_parse_ls (const char *file, const enum stype system_type)
       return ftp_parse_vms_ls (file);
     case ST_MACOS:
       return ftp_parse_unix_ls (file, 1);
+    case ST_OS9:
+      return ftp_parse_os9_ls (file);
     default:
       logprintf (LOG_NOTQUIET, _("\
 Unsupported listing type, trying Unix listing parser.\n"));
diff --git a/src/ftp.c b/src/ftp.c
index 80420ef..34b6025 100644
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -596,6 +596,11 @@ Error in server response, closing control connection.\n"));
           con->st |= LIST_AFTER_LIST_A_CHECK_DONE;
           con->st |= AVOID_LIST_A;
           break;
+        case ST_OS9:
+          DEBUGP (("\nOS/9: I know it and I will use \"LIST -a\" as standard list command\n"));
+          con->st |= LIST_AFTER_LIST_A_CHECK_DONE;
+          con->st |= AVOID_LIST;
+          break;
         case ST_UNIX:
           if (con->rsu == UST_MULTINET)
             {
diff --git a/src/ftp.h b/src/ftp.h
index 84ded26..92eb81a 100644
--- a/src/ftp.h
+++ b/src/ftp.h
@@ -43,6 +43,7 @@ enum stype
   ST_WINNT,
   ST_MACOS,
   ST_OS400,
+  ST_OS9,
   ST_OTHER
 };
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d3bb6a5..0e01d44 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -67,6 +67,7 @@ PX_TESTS = \
              Test-ftp-iri-recursive.px \
              Test-ftp-iri-disabled.px \
              Test-ftp-list-Multinet.px \
+             Test-ftp-list-OS9.px \
              Test-ftp-list-Unknown.px \
              Test-ftp-list-Unknown-a.px \
              Test-ftp-list-Unknown-hidden.px \
-- 
2.6.1

Reply via email to