FtpClient.BeginDereferenceLink Method (FtpListItem, AsyncCallback, Object)

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Derefence a FtpListItem object asynchronously. See the MaximumDereferenceCount property for controlling how deep this method will recurse before giving up.

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

Syntax

C#
public IAsyncResult BeginDereferenceLink(
	FtpListItem item,
	AsyncCallback callback,
	Object state
)
Visual Basic
Public Function BeginDereferenceLink ( 
	item As FtpListItem,
	callback As AsyncCallback,
	state As Object
) As IAsyncResult
Visual C++
public:
IAsyncResult^ BeginDereferenceLink(
	FtpListItem^ item, 
	AsyncCallback^ callback, 
	Object^ state
)

Parameters

item
Type: System.Net.FtpClient..::..FtpListItem
The item to derefence
callback
Type: System..::..AsyncCallback
AsyncCallback
state
Type: System..::..Object
State Object

Return Value

Type: IAsyncResult
IAsyncResult

Examples

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

namespace Examples {
    /// <summary>
    /// This example illustrates how to dereference a symbolic link asyncrhonously. The
    /// code bollow takes a FtpListItem object and checks if it is a symbolic link and
    /// that the LinkTarget property has been initalized before executing the method. Not
    /// doing so can result in a FtpException being thrown.
    /// 
    /// Also see the DerefenceLink() example! There is lots of information
    /// not mentioned here!
    /// </summary>
    static class BeginDereferenceLink {
        static ManualResetEvent m_reset = new ManualResetEvent(false);

        public static void BeginDereferenceLinkExample(FtpListItem item) {
            using (FtpClient conn = new FtpClient()) {
                m_reset.Reset();

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

                if (item.Type == FtpFileSystemObjectType.Link && item.LinkTarget != null) {
                    conn.BeginDereferenceLink(item, new AsyncCallback(DereferenceLinkCallback), conn);
                    m_reset.WaitOne();
                }

                conn.Disconnect();
            }
        }

        static void DereferenceLinkCallback(IAsyncResult ar) {
            FtpClient conn = ar.AsyncState as FtpClient;
            FtpListItem target;

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

                target = conn.EndDereferenceLink(ar);
                if (target != null) {
                    // success...
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
            finally {
                m_reset.Set();
            }
        }
    }
}

See Also