FtpClient.GetFileSize Method

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Gets the size of the file

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

Syntax

C#
public virtual long GetFileSize(
	string path
)
Visual Basic
Public Overridable Function GetFileSize ( 
	path As String
) As Long
Visual C++
public:
virtual long long GetFileSize(
	String^ path
)

Parameters

path
Type: System..::..String
The full or relative path of the file

Return Value

Type: Int64
-1 if the command fails, otherwise the file size

Implements

IFtpClient..::..GetFileSize(String)

Examples

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

namespace Examples {
    static class GetFileSizeExample {
        public static void GetFileSize() {
            using (FtpClient conn = new FtpClient()) {
                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                Console.WriteLine("The file size is: {0}",
                    conn.GetFileSize("/full/or/relative/path/to/file"));
            }
        }
    }
}

See Also