FtpClient.BeginGetListing Method (String, FtpListOption, AsyncCallback, Object)

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Gets a file listing from the server asynchronously

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

Syntax

C#
public IAsyncResult BeginGetListing(
	string path,
	FtpListOption options,
	AsyncCallback callback,
	Object state
)
Visual Basic
Public Function BeginGetListing ( 
	path As String,
	options As FtpListOption,
	callback As AsyncCallback,
	state As Object
) As IAsyncResult
Visual C++
public:
virtual IAsyncResult^ BeginGetListing(
	String^ path, 
	FtpListOption options, 
	AsyncCallback^ callback, 
	Object^ state
) sealed

Parameters

path
Type: System..::..String
The path to list
options
Type: System.Net.FtpClient..::..FtpListOption
Options that dictate how the list operation is performed
callback
Type: System..::..AsyncCallback
AsyncCallback method
state
Type: System..::..Object
State object

Return Value

Type: IAsyncResult
IAsyncResult

Implements

IFtpClient..::..BeginGetListing(String, FtpListOption, AsyncCallback, Object)

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