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

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Checks if a file exsts on the server by taking a file listing of the parent directory in the path and comparing the results the path supplied.

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

Syntax

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

Parameters

path
Type: System..::..String
The full or relative path to the file
options
Type: System.Net.FtpClient..::..FtpListOption
Options for controling the file listing used to determine if the file exists.
callback
Type: System..::..AsyncCallback
Async callback
state
Type: System..::..Object
State object

Return Value

Type: IAsyncResult
IAsyncResult

Implements

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

Examples

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

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

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

                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                conn.Connect();
                conn.BeginFileExists("foobar", new AsyncCallback(BeginFileExistsCallback), conn);

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

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

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

                Console.WriteLine("File exists: {0}", conn.EndFileExists(ar));
            }
            catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
            finally {
                m_reset.Set();
            }
        }
    }
}

See Also