Sure, download the source for edtFTPnet and take a look at the parsers in there.
Thanks, i looked at the parser's code. I have the following code:
public class TestFileFactory : FTPFileFactory
{
public TestFileFactory(TestFileParser parser)
{
FileParser = parser;
}
public override FTPFile[] Parse(string[] fileStrings)
{
Console.WriteLine("factory->parse");
return base.Parse(fileStrings);
}
public override FTPFile PartialParse(string fileString, System.Collections.ArrayList allFileStrings)
{
Console.WriteLine("factory->partialparse");
return base.PartialParse(fileString, allFileStrings);
}
}
public class TestFileParser : FTPFileParser
{
public override bool TimeIncludesSeconds
{
get { return false; }
}
public override string ToString()
{
return "Test";
}
public override bool IsValidFormat(string[] listing)
{
return false;
}
public override FTPFile Parse(string raw)
{
Console.WriteLine("parser->parse");
DateTime dt = DateTime.Now;
return new FTPFile(0, raw, "test", 10, false, ref dt);
}
}
static void Main()
{
var ftpConnection = new SecureFTPConnection();
// connection init
ftpConnection.Protocol = FileTransferProtocol.SFTP;
ftpConnection.FileInfoParser = new TestFileFactory(new TestFileParser());
ftpConnection.ServerValidation = SecureFTPServerValidationType.None;
ftpConnection.Connect();
FTPFile[] files = ftpConnection.GetFileInfos();
// At this moment - no any output from parse methods, so i assume
List<FTPFile> data = files.Select(ftpFile => ftpConnection.FileInfoParser.FileParser.Parse(ftpFile.Raw)).ToList();
// At this moment - i have output from parser->parse
// ... work with data and closing connection
}
So, the my question: is it right to use custom parser this way? Custom factory and custom parser are not called on GetFileInfos, so i called my parser's Parse method manually on collection of FTPFile gathered by GetFileInfos method. It works on casual server listing but what will happen when server will answer with non-standard response? Will GetFileInfos return me FTPFile collection with raw data even if it can't parse that data? Thanks.