Преглед на файлове

Use SSH_FXP_LSTAT to determine whether a given file or directory exists.
Fixes issues #1952, #1696 and #1574.

Gert Driesen преди 11 години
родител
ревизия
d769506f31
променени са 2 файла, в които са добавени 25 реда и са изтрити 3 реда
  1. 1 0
      Renci.SshClient/Build/nuget/SSH.NET.nuspec
  2. 24 3
      Renci.SshClient/Renci.SshNet/SftpClient.cs

+ 1 - 0
Renci.SshClient/Build/nuget/SSH.NET.nuspec

@@ -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
Renci.SshClient/Renci.SshNet/SftpClient.cs

@@ -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>