FtpClient.BeginExecute Method

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Performs an asynchronouse execution of the specified command

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

Syntax

C#
public IAsyncResult BeginExecute(
	string command,
	AsyncCallback callback,
	Object state
)
Visual Basic
Public Function BeginExecute ( 
	command As String,
	callback As AsyncCallback,
	state As Object
) As IAsyncResult
Visual C++
public:
virtual IAsyncResult^ BeginExecute(
	String^ command, 
	AsyncCallback^ callback, 
	Object^ state
) sealed

Parameters

command
Type: System..::..String
The command to execute
callback
Type: System..::..AsyncCallback
The AsyncCallback method
state
Type: System..::..Object
State object

Return Value

Type: IAsyncResult
IAsyncResult

Implements

IFtpClient..::..BeginExecute(String, AsyncCallback, Object)

Examples

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

namespace Examples {
    public class BeginExecuteExample {
        static ManualResetEvent m_reset = new ManualResetEvent(false);

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

                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                conn.Connect();
                conn.BeginExecute("SYST", new AsyncCallback(BeginExecuteCallback), conn);

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

        static void BeginExecuteCallback(IAsyncResult ar) {
            FtpClient conn = ar.AsyncState as FtpClient;
            FtpReply reply;

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

                reply = conn.EndExecute(ar);
                if (!reply.Success)
                    throw new FtpCommandException(reply);

                Console.WriteLine(reply.Message);
            }
            catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
            finally {
                m_reset.Set();
            }
        }
    }
}

See Also