The ParsingListingLine event is raised when a listing line is received from the FTP server. Contrary to other events which are subscribed to by creating an instance of a FileSystemEvents class, the ParsingListingLine event can only be subscribed to via the FtpConnection instance. If any other events are required, an instance of the FileSystemEvents class must be created and the desired events subscribed to.
Xceed FTP for .NET currently provides automatic support for listing the contents of AS400, DOS (Windows), UNIX and VMS FTP servers when calling the GetItems, GetFiles, or GetFolders methods. To modify or manually parse the listing lines returned by the FTP server, the ParsingListingLine event can be used, or a new listing parser added to the FTP connection's ListingParsers collection .
Basic steps
To subscribe to the ParsingListingLine event, the following steps must be performed:
-
Create an instance of the FtpConnection class.
-
Subscribe to the ParsingListingLine event.
The following example demonstrates how use the ParsingListingLine event to manually parse the listing lines returned by an FTP server to remove the potential "." and ".." items.
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
using Xceed.FileSystem; |
Custom line parsers
Usually, if you only want to modify or filter the listing lines returned by the GetItems, GetFiles, or GetFolders methods, you would handle the ParsingListingLine event rather than creating a listing parser. If however, you want to support the listing lines returned by an FTP server that is not automatically supported by Xceed FTP for .NET, then your best option would be to create a listing parser as it will make it easier to reuse your code.
To create a custom listing parser, create a class that derives from the FtpListingParser class and override the ParseLine method. In the ParseLine method, parse the line that is received as a parameter to create and return a new FtpItemInfo object that contains the FTP item's information. Once you have your custom listing parser, add it to the FTP connection's ListingParsers collection.