Browse Source

Bug 1778: Configurable S3 root path/bucket in .NET assembly

https://winscp.net/tracker/1778

Source commit: 64c8280512ca144e0fe8a1944832997550579b02
Martin Prikryl 6 years ago
parent
commit
3b88e296ab
2 changed files with 15 additions and 13 deletions
  1. 4 4
      dotnet/Session.cs
  2. 11 9
      dotnet/SessionOptions.cs

+ 4 - 4
dotnet/Session.cs

@@ -1747,14 +1747,14 @@ namespace WinSCP
                     tail += ":" + sessionOptions.PortNumber.ToString(CultureInfo.InvariantCulture);
                     tail += ":" + sessionOptions.PortNumber.ToString(CultureInfo.InvariantCulture);
                 }
                 }
 
 
-                if (!string.IsNullOrEmpty(sessionOptions.WebdavRoot) && !scanFingerprint)
+                if (!string.IsNullOrEmpty(sessionOptions.RootPath) && !scanFingerprint)
                 {
                 {
-                    if (sessionOptions.Protocol != Protocol.Webdav)
+                    if ((sessionOptions.Protocol != Protocol.Webdav) && (sessionOptions.Protocol != Protocol.S3))
                     {
                     {
-                        throw Logger.WriteException(new ArgumentException("SessionOptions.WebdavRoot is set, but SessionOptions.Protocol is not Protocol.Webdav."));
+                        throw Logger.WriteException(new ArgumentException("SessionOptions.RootPath is set, but SessionOptions.Protocol is not Protocol.Webdav nor Protocol.S3."));
                     }
                     }
 
 
-                    tail += sessionOptions.WebdavRoot;
+                    tail += sessionOptions.RootPath;
                 }
                 }
 
 
                 url += tail;
                 url += tail;

+ 11 - 9
dotnet/SessionOptions.cs

@@ -59,6 +59,7 @@ namespace WinSCP
         public int TimeoutInMilliseconds { get { return Tools.TimeSpanToMilliseconds(Timeout); } set { Timeout = Tools.MillisecondsToTimeSpan(value); } }
         public int TimeoutInMilliseconds { get { return Tools.TimeSpanToMilliseconds(Timeout); } set { Timeout = Tools.MillisecondsToTimeSpan(value); } }
         public string PrivateKeyPassphrase { get { return GetPassword(_securePrivateKeyPassphrase); } set { SetPassword(ref _securePrivateKeyPassphrase, value); } }
         public string PrivateKeyPassphrase { get { return GetPassword(_securePrivateKeyPassphrase); } set { SetPassword(ref _securePrivateKeyPassphrase, value); } }
         public SecureString SecurePrivateKeyPassphrase { get { return _securePrivateKeyPassphrase; } set { _securePrivateKeyPassphrase = value; } }
         public SecureString SecurePrivateKeyPassphrase { get { return _securePrivateKeyPassphrase; } set { _securePrivateKeyPassphrase = value; } }
+        public string RootPath { get { return _rootPath; } set { SetRootPath(value); } }
 
 
         // SSH
         // SSH
         public string SshHostKeyFingerprint { get { return _sshHostKeyFingerprint; } set { SetSshHostKeyFingerprint(value); } }
         public string SshHostKeyFingerprint { get { return _sshHostKeyFingerprint; } set { SetSshHostKeyFingerprint(value); } }
@@ -73,7 +74,8 @@ namespace WinSCP
 
 
         // WebDAV
         // WebDAV
         public bool WebdavSecure { get; set; }
         public bool WebdavSecure { get; set; }
-        public string WebdavRoot { get { return _webdavRoot; } set { SetWebdavRoot(value); } }
+        [Obsolete("Use RootPath")]
+        public string WebdavRoot { get { return RootPath; } set { RootPath = value; } }
 
 
         // TLS
         // TLS
         public string TlsHostCertificateFingerprint { get { return _tlsHostCertificateFingerprint; } set { SetHostTlsCertificateFingerprint(value); } }
         public string TlsHostCertificateFingerprint { get { return _tlsHostCertificateFingerprint; } set { SetHostTlsCertificateFingerprint(value); } }
@@ -108,7 +110,7 @@ namespace WinSCP
 
 
             url = url.Substring(index + protocolSeparator.Length).Trim();
             url = url.Substring(index + protocolSeparator.Length).Trim();
             index = url.IndexOf('/');
             index = url.IndexOf('/');
-            WebdavRoot = null;
+            RootPath = null;
             if (index >= 0)
             if (index >= 0)
             {
             {
                 string path = url.Substring(index).Trim();
                 string path = url.Substring(index).Trim();
@@ -117,11 +119,11 @@ namespace WinSCP
                 path = CutToChar(ref parameters, ';');
                 path = CutToChar(ref parameters, ';');
                 if (!string.IsNullOrEmpty(path) && (path != "/"))
                 if (!string.IsNullOrEmpty(path) && (path != "/"))
                 {
                 {
-                    if (Protocol != Protocol.Webdav)
+                    if ((Protocol != Protocol.Webdav) && (Protocol != Protocol.S3))
                     {
                     {
-                        throw new ArgumentException("Root folder can be specified for WebDAV protocol only", "url");
+                        throw new ArgumentException("Root path can be specified for WebDAV and S3 protocols only", "url");
                     }
                     }
-                    WebdavRoot = path;
+                    RootPath = path;
                 }
                 }
 
 
                 // forward compatibility
                 // forward compatibility
@@ -390,13 +392,13 @@ namespace WinSCP
             }
             }
         }
         }
 
 
-        private void SetWebdavRoot(string value)
+        private void SetRootPath(string value)
         {
         {
             if (!string.IsNullOrEmpty(value) && (value[0] != '/'))
             if (!string.IsNullOrEmpty(value) && (value[0] != '/'))
             {
             {
-                throw new ArgumentException("WebDAV root path has to start with slash");
+                throw new ArgumentException("Root path has to start with a slash");
             }
             }
-            _webdavRoot = value;
+            _rootPath = value;
         }
         }
 
 
         private static void SetPassword(ref SecureString securePassword, string value)
         private static void SetPassword(ref SecureString securePassword, string value)
@@ -473,7 +475,7 @@ namespace WinSCP
         private string _tlsHostCertificateFingerprint;
         private string _tlsHostCertificateFingerprint;
         private TimeSpan _timeout;
         private TimeSpan _timeout;
         private int _portNumber;
         private int _portNumber;
-        private string _webdavRoot;
+        private string _rootPath;
         private Protocol _protocol;
         private Protocol _protocol;
         private string _name;
         private string _name;