I'm using your awesome edtFTPnet/Free library and am working with an FTP server running on MVS (z/OS). The FTP server returns a few different directory listing formats depending on the options currently in use or the format of the argument passed to the DIR sub-command.
I planned on creating a set of custom parsers to handle each format. I started by creating my own MvsFileParser class (inheriting from FTPFileParser) to handle just the directory listing format for a list of members within a partitioned data set. I thought I was on the right track by doing so and adding an instance of the custom parser to my FTPConnection object via the FTPConnection.FileInfoPaser.AddParser() method. The problem I'm running into is when the FTPFileFactory cycles through the parsers during parser detection, the UnixFileParser's IsValidFormat method is throwing an exception when processing the directory listing.
The first two lines of the directory listing are as follows:
Name VV.MM Created Changed Size Init Mod Id
Z 01.00 2010/06/06 2010/06/06 23:13 43 43 0 XXXXXX
By tracing through the code I see that the UnixFileParser.IsValidFormat method is choking on the second line of the directory listing because after it breaks the line into fields, the first field "Z" is only one character long and there are some checks that assume that the first field length is at least 2 (or, depending on if it gets to the last chance check, 3) characters in length.
The UnixFileParser.IsValidFormat method throws an exception when it tries to set the variable ch01, because it assumes the first field has at least two characters. The Char.ToLower(fields[0][1]) call is the statement which causes the exception in this case.
A similar situation could arise in the next if statement where one of the checks is "fields[0].IndexOf('-', 2) > 0" in which case the length of the first field would need to be at least three characters due to the specified starting index of 2 in the IndexOf method call.
I can get around this by modifying the UnixFileParser.IsValidFormat method with appropriate length checks in the necessary spots and recompiling, however, my second thought was that maybe I should be doing this differently.
Is there a way to remove the parsers I know I won't be needing (e.g. the Unix, Windows, etc. parsers)? Or am I on the wrong track in the way I'm implementing my custom file parser. It's possible that I missed something and maybe should be doing it a different way, like creating a custom FTPFileFactory as well?
There wouldn't happen to be any quick reference guide to creating/implementing your own custom listing parsers? I checked around on your site, forums, blog but didn't find anything. Any help to point me in the right direction would be much appreciated.
Thanks,
Robert