File Exists

Top  Previous  Next

Checking if a file exists on the FTP server.

 

 

[C#]

// create new Ftp instance

Ftp ftp = new Ftp(hostname, username, password, port);

 

// establish connection

ftp.Connect();

 

String file = "filename.txt";

 

// detects whether the specified file exists.

if (ftp.FileExists(file)) {

 Console.WriteLine("The file {0} exists", file);

} else {

 Console.WriteLine("The file {0} not exists", file);

}

 

 

[Visual Basic]

' create new Ftp instance

Dim ftp As Ftp = New Ftp(hostname, username, password, port)

 

' establish connection

ftp.Connect()

 

Dim file As String = "filename.txt"

 

' detects whether the specified file exists.

If ftp.FileExists(file) Then

 Console.WriteLine("The file {0} exists", file)

Else

 Console.WriteLine("The file {0} not exists", file)

End If