FtpClient.EndGetListing Method

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Ends an asynchronous file listing

Namespace: System.Net.FtpClient
Assembly: System.Net.FtpClient (in System.Net.FtpClient.dll) Version: 1.0.5064.17461

Syntax

C#
public FtpListItem[] EndGetListing(
	IAsyncResult ar
)
Visual Basic
Public Function EndGetListing ( 
	ar As IAsyncResult
) As FtpListItem()
Visual C++
public:
virtual array<FtpListItem^>^ EndGetListing(
	IAsyncResult^ ar
) sealed

Parameters

ar
Type: System..::..IAsyncResult
IAsyncResult return from BeginGetListing()

Return Value

Type: array<FtpListItem>[]()[][]
An array of items retrieved in the listing

Implements

IFtpClient..::..EndGetListing(IAsyncResult)

Examples

C#  Copy imageCopy
using System;
using System.Net;
using System.Net.FtpClient;
using System.Threading;

namespace Examples {
    // Also see the GetListing() example for more details
    // about file listings and the objects returned.
    public static class BeginGetListing {
        static ManualResetEvent m_reset = new ManualResetEvent(false);

        public static void BeginGetListingExample() {
            using (FtpClient conn = new FtpClient()) {
                m_reset.Reset();

                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                conn.Connect();
                conn.BeginGetListing(new AsyncCallback(GetListingCallback), conn);

                m_reset.WaitOne();
                conn.Disconnect();
            }
        }

        static void GetListingCallback(IAsyncResult ar) {
            FtpClient conn = ar.AsyncState as FtpClient;

            try {
                if (conn == null)
                    throw new InvalidOperationException("The FtpControlConnection object is null!");

                foreach (FtpListItem item in conn.EndGetListing(ar))
                    Console.WriteLine(item);
            }
            catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
            finally {
                m_reset.Set();
            }
        }
    }
}

See Also