FtpClient.EndGetFileSize Method

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Ends a call to BeginGetFileSize()

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

Syntax

C#
public long EndGetFileSize(
	IAsyncResult ar
)
Visual Basic
Public Function EndGetFileSize ( 
	ar As IAsyncResult
) As Long
Visual C++
public:
virtual long long EndGetFileSize(
	IAsyncResult^ ar
) sealed

Parameters

ar
Type: System..::..IAsyncResult
IAsyncResult returned from BeginGetFileSize

Return Value

Type: Int64
The size of the file, -1 if there was a problem.

Implements

IFtpClient..::..EndGetFileSize(IAsyncResult)

Examples

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

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

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

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

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

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

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

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

See Also