Use SSH_FXP_LSTAT to determine whether a given file or directory exists.

Fixes issues #1952, #1696 and #1574.
This commit is contained in:
Gert Driesen
2014-05-04 19:05:35 +00:00
parent 43836a5b50
commit d769506f31
2 changed files with 25 additions and 3 deletions
@@ -21,6 +21,7 @@ New Features:
Fixes:
* Client channels are no longer closed on dispose (issue #1943)
* SftpClient.Exists(string) returns true for a path that does not exist (issues #1952, #1696 and #1574)
2014.4.6-beta1
==============
+24 -3
View File
@@ -538,13 +538,34 @@ namespace Renci.SshNet
if (this._sftpSession == null)
throw new SshConnectionException("Client not connected.");
var fullPath = this._sftpSession.GetFullRemotePath(path);
var fullPath = this._sftpSession.GetCanonicalPath(path);
if (this._sftpSession.RequestRealPath(fullPath, true) == null)
// using SSH_FXP_REALPATH is not an alternative the SFTP specification has not always
// been clear on how the server should respond when the specified path is not present
// on the server:
//
// SSH 1 to 4:
// No mention of how the server should respond if the path is not present on the server.
//
// SSH 5:
// The server SHOULD fail the request if the path is not present on the server.
//
// SSH 6:
// Draft 06: The server SHOULD fail the request if the path is not present on the server.
// Draft 07 to 13: The server MUST NOT fail the request if the path does not exist.
//
// Note that SSH 6 (draft 06 and forward) allows for more control options, but we
// currently only support up to v3.
try
{
_sftpSession.RequestLStat(fullPath);
return true;
}
catch (SftpPathNotFoundException)
{
return false;
}
return true;
}
/// <summary>