This is an old revision of the document!
Session.FileExists Method
Checks for existence of remote file.
This feature is available only in the latest beta release.
With WinSCP 5.0.7 beta the method always fails with InvalidOperationException
with message “Recursive calls not allowed”. As a workaround, use following extension method or equivalent:
public static bool FileExistsFix(this Session session, string path) { try { session.GetFileInfo(path); return true; } catch (SessionRemoteException) { return false; } }
Advertisement
Syntax
C#
public bool FileExists(string path)
VB.NET
Public Function FileExists(ByVal path As String) As Boolean
Parameters
Name | Description |
---|---|
string path | Full path to remote file. |
Return Value
true
if file exists, false
otherwise.
Exceptions
Exception | Condition |
---|---|
InvalidOperationException | Session is not opened. |
SessionLocalException | Error communicating with winscp.com . See the exception documentation for details. |
SessionRemoteException | Session has failed. Command has failed. See the exception documentation for details. |
TimeoutException | Timeout waiting for winscp.com to respond. |
Advertisement
Example
See example for Session.GetFiles
.