PowerTCP FTP for .NET
Listing Event
Example 



Raised when Marshal(Listing,String,Object) is used.
Syntax
Public Event Listing As EventHandler(Of ListingEventArgs)
Dim instance As Ftp
Dim handler As EventHandler(Of ListingEventArgs)
 
AddHandler instance.Listing, handler
public event EventHandler<ListingEventArgs> Listing
public:
event EventHandler<ListingEventArgs^>^ Listing
Event Data

The event handler receives an argument of type ListingEventArgs containing data related to this event. The following ListingEventArgs properties provide information specific to this event.

PropertyDescription
Message Returns the message argument provided by the Marshal method. (Inherited from Dart.Ftp.UserStateEventArgs)
UserState Returns the user state argument provided by the Marshal method. (Inherited from Dart.Ftp.UserStateEventArgs)
Remarks
See the SynchronizingObject property for information on updating UI controls in your event handler.
Example
This example demonstrates using the FTP control to obtain a directory listing from a remote server.
private void getListing()
{
    //Setup the Ftp session and then connect, authenticate, and retrieve a listing on a worker thread
    ftp1.Session.RemoteEndPoint.HostNameOrAddress = myServer;
    ftp1.Session.Username = myUsername;
    ftp1.Session.Password = myPassword;

    //Wire up the Listing event to receive the listing on the UI thread
    ftp1.Listing += new EventHandler<ListingEventArgs>(ftp1_Listing);

    //The Start method executes the listing operation on a worker thread so the UI is not blocked.
    //Worker thread Exceptions are automatically caught and marshaled to the Error event
    ftp1.Start(getListingWorker, null);
}

private void getListingWorker(object state)
{
    try
    {
        //Login to a server and get a listing
        ftp1.Connect();
        ftp1.Authenticate();
        Listing listing = ftp1.List("", "", ListType.Full);

        //Marshal the listing to the UI thread
        ftp1.Marshal(listing, "", null);
    }
    finally
    {
        //Logout of the server
        ftp1.Close();
    }
}

private void ftp1_Listing(object sender, ListingEventArgs e)
{
    //Add all the list entries in the listing to a listbox
    foreach (ListEntry entry in e.Listing)
        listBox1.Items.Add(entry.Text);
}
Private Sub getListing()
    'Setup the Ftp session and then connect, authenticate, and retrieve a listing on a worker thread
    ftp1.Session.RemoteEndPoint.HostNameOrAddress = myServer
    ftp1.Session.Username = myUsername
    ftp1.Session.Password = myPassword

    'Wire up the Listing event to receive the listing on the UI thread
    AddHandler ftp1.Listing, AddressOf ftp1_Listing

    'The Start method executes the listing operation on a worker thread so the UI is not blocked.
    'Worker thread Exceptions are automatically caught and marshaled to the Error event
    ftp1.Start(AddressOf getListingWorker, Nothing)
End Sub

Private Sub getListingWorker(ByVal state As Object)
    Try
        'Login to a server and get a listing
        ftp1.Connect()
        ftp1.Authenticate()
        Dim listing As Listing = ftp1.List("", "", ListType.Full)

        'Marshal the listing to the UI thread
        ftp1.Marshal(listing, "", Nothing)
    Catch ex As Exception
        ftp1.Marshal(ex)
    Finally
        'Logout of the server
        ftp1.Close()
    End Try
End Sub

Private Sub ftp1_Listing(ByVal sender As Object, ByVal e As ListingEventArgs)
    'Add all the list entries in the listing to a listbox
    For Each entry As ListEntry In e.Listing
        listBox1.Items.Add(entry.Text)
    Next entry
End Sub
See Also

Reference

Ftp Class
Ftp Members


PowerTCP FTP for .NET Documentation Version 6.1
© 2023 Dart Communications. All Rights Reserved.
Send comments on this topic