FtpClient.FileExists Method (String)

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 bool FileExists(
	string path
)
Visual Basic
Public Function FileExists ( 
	path As String
) As Boolean
Visual C++
public:
virtual bool FileExists(
	String^ path
) sealed

Parameters

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

Return Value

Type: Boolean
True if the file exists

Implements

IFtpClient..::..FileExists(String)

Examples

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

namespace Examples {
    static class FileExistsExample {
        public static void FileExists() {
            using (FtpClient conn = new FtpClient()) {
                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");

                // The last parameter forces System.Net.FtpClient to use LIST -a 
                // for getting a list of objects in the parent directory.
                if (conn.FileExists("/full/or/relative/path", 
                    FtpListOption.ForceList | FtpListOption.AllFiles)) {
                    // dome something
                }
            }
        }
    }
}

See Also