FtpClient.FileExists Method (String, FtpListOption)

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

Return Value

Type: Boolean
True if the file exists

Implements

IFtpClient..::..FileExists(String, FtpListOption)

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