Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
6k views
in Java FTP by
Hello,

Using Version 1.4.4, I am trying to call dirDetails() on a SunOS 5.8 server, and at first I was getting the following:

java.text.ParseException: Unexpected number of fields: 2
at com.enterprisedt.net.ftp.WindowsFileParser.parse WindowsFileParser.java:87)
at com.enterprisedt.net.ftp.FTPFileFactory.parse(FTPFileFactory.java:169)
at com.enterprisedt.net.ftp.FTPClient.dirDetails(FTPClient.java:1735)


I found "WindowsFileParser" strange because my FTP-server is a Unix machine, so I overwrote the parser:

setFTPFileFactory(new FTPFileFactory(new UnixFileParser()));


Now I am getting:

java.text.ParseException: Unexpected number of fields in listing 'Gesamt 8' - expected minimum 8 fields but found 2 fields


OK, now we are getting somewhere. When I do dir(".", true), I get:

Gesamt 8
drwxrwxr-x 4 nbctrl notebook 512 Sep 16 10:55 .
drwxrwx--- 9 nbctrl notebook 512 Sep 16 11:27 ..
drwxrwxr-x 3 nbctrl notebook 512 Sep 16 10:56 dir11
drwxrwxr-x 2 nbctrl notebook 512 Sep 16 10:57 dir12
-rw-rw-r-- 1 nbctrl notebook 16 Sep 16 10:54 file1.txt


It seems, both parsers are not able to deal with "Gesamt 8", which is German for "total 8". Your parsers probably skip any line that starts with "total", but in my case the word is not "total".

How can I overwrite this behavior? I could write a whole new parser, but I don't want to implement functionality that you already have. Is there a way to overwrite a method on UnixFileParser ? I do not have the source code...

Thank you very much for any help,
Bojidar

2 Answers

0 votes
by
Hi,

the following will work:

class GermanUnixFileParser
  extends UnixFileParser
{
  public FTPFile parse(java.lang.String raw)
    throws java.text.ParseException
  {
    if (raw.startsWith("Gesamt"))
    {
      return null;
    }

    return super.parse(raw);
  }
}


but I don't consider it to be the best solution. How do your parsers skip the "total" line? How about:
- completely ignore the first line
- ignore all line that do not start with 'd' or '-'
- a third method in FTPFileParser that defines which line are to be ignored

Maybe you will have an even better answer. Thanks in advance,
Bojidar
0 votes
by (162k points)
I think you've come up with possibly the best solution - ignore lines that do not start with 'd' or '-'. In addition, lines can also begin with 'l' if they are symlinks.

Thanks - we'll modify the code to do this.

How do your parsers skip the "total" line? How about:
- completely ignore the first line
- ignore all line that do not start with 'd' or '-'
- a third method in FTPFileParser that defines which line are to be ignored

Maybe you will have an even better answer. Thanks in advance,
Bojidar

Categories

...