diff --git a/src/Kp2aBusinessLogic/Io/NetFtpFileStorage.cs b/src/Kp2aBusinessLogic/Io/NetFtpFileStorage.cs index 0dd18038..fdac3a46 100644 --- a/src/Kp2aBusinessLogic/Io/NetFtpFileStorage.cs +++ b/src/Kp2aBusinessLogic/Io/NetFtpFileStorage.cs @@ -3,12 +3,12 @@ using System; using System.Collections.Generic; using System.IO; using System.Net; -using System.Net.FtpClient; using System.Reflection; using System.Threading; using Android.Content; using Android.OS; using Android.Preferences; +using FluentFTP; using KeePassLib; using KeePassLib.Serialization; using KeePassLib.Utility; @@ -17,73 +17,6 @@ namespace keepass2android.Io { public class NetFtpFileStorage: IFileStorage { - class RetryConnectFtpClient : FtpClient - { - protected override FtpClient CloneConnection() - { - RetryConnectFtpClient conn = new RetryConnectFtpClient(); - - conn.m_isClone = true; - - foreach (PropertyInfo prop in GetType().GetProperties()) - { - object[] attributes = prop.GetCustomAttributes(typeof(FtpControlConnectionClone), true); - - if (attributes != null && attributes.Length > 0) - { - prop.SetValue(conn, prop.GetValue(this, null), null); - } - } - - // always accept certficate no matter what because if code execution ever - // gets here it means the certificate on the control connection object being - // cloned was already accepted. - conn.ValidateCertificate += new FtpSslValidation( - delegate(FtpClient obj, FtpSslValidationEventArgs e) - { - e.Accept = true; - }); - - return conn; - } - - private static T DoInRetryLoop(Func func) - { - double timeout = 30.0; - double timePerRequest = 1.0; - var startTime = DateTime.Now; - while (true) - { - var attemptStartTime = DateTime.Now; - try - { - return func(); - } - catch (System.Net.Sockets.SocketException e) - { - if ((e.ErrorCode != 10061) || (DateTime.Now > startTime.AddSeconds(timeout))) - { - throw; - } - double secondsSinceAttemptStart = (DateTime.Now - attemptStartTime).TotalSeconds; - if (secondsSinceAttemptStart < timePerRequest) - { - Thread.Sleep(TimeSpan.FromSeconds(timePerRequest - secondsSinceAttemptStart)); - } - } - } - } - public override void Connect() - { - DoInRetryLoop(() => - { - base.Connect(); - return true; - } - ); - } - } - public struct ConnectionSettings { public FtpEncryptionMode EncryptionMode {get; set; } @@ -149,7 +82,6 @@ namespace keepass2android.Io { _app = app; traceStream = new MemoryStream(); - FtpTrace.AddListener(new System.Diagnostics.TextWriterTraceListener(traceStream)); } @@ -174,7 +106,7 @@ namespace keepass2android.Io { string localPath = IocToUri(ioc).PathAndQuery; if (client.DirectoryExists(localPath)) - client.DeleteDirectory(localPath, true); + client.DeleteDirectory(localPath); else client.DeleteFile(localPath); } @@ -205,7 +137,8 @@ namespace keepass2android.Io { var settings = ConnectionSettings.FromIoc(ioc); - FtpClient client = new RetryConnectFtpClient(); + FtpClient client = new FtpClient(); + client.RetryAttempts = 3; if ((settings.Username.Length > 0) || (settings.Password.Length > 0)) client.Credentials = new NetworkCredential(settings.Username, settings.Password); else diff --git a/src/Kp2aBusinessLogic/Kp2aBusinessLogic.csproj b/src/Kp2aBusinessLogic/Kp2aBusinessLogic.csproj index e14a1d8e..7569a28b 100644 --- a/src/Kp2aBusinessLogic/Kp2aBusinessLogic.csproj +++ b/src/Kp2aBusinessLogic/Kp2aBusinessLogic.csproj @@ -141,10 +141,6 @@ {70D3844A-D9FA-4A64-B205-A84C6A822196} KP2AKdbLibraryBinding - - {146FD497-BA03-4740-B6C5-5C84EA8FCDE2} - System.Net.FtpClient.Android - {5CF675A5-9BEE-4720-BED9-D5BF14A2EBF9} TwofishCipher @@ -157,6 +153,9 @@ + + 27.1.3 + 1.17.0 diff --git a/src/keepass2android/FileSelectHelper.cs b/src/keepass2android/FileSelectHelper.cs index 695df13d..efd8d1d2 100644 --- a/src/keepass2android/FileSelectHelper.cs +++ b/src/keepass2android/FileSelectHelper.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; #if !NoNet -using System.Net.FtpClient; +using FluentFTP; #endif using System.Text; @@ -12,6 +12,7 @@ using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget; + using Java.IO; using keepass2android.Io; using Keepass2android.Javafilestorage; diff --git a/src/keepass2android/keepass2android.csproj b/src/keepass2android/keepass2android.csproj index 0caabd96..c8216da6 100644 --- a/src/keepass2android/keepass2android.csproj +++ b/src/keepass2android/keepass2android.csproj @@ -103,6 +103,9 @@ + + ..\packages\FluentFTP.27.1.3\lib\netstandard1.6\FluentFTP.dll + @@ -967,10 +970,6 @@ {A8779D4D-7C49-4C2F-82BD-2CDC448391DA} Kp2aKeyboardBinding - - {146FD497-BA03-4740-B6C5-5C84EA8FCDE2} - System.Net.FtpClient.Android - {3DA3911E-36DE-465E-8F15-F1991B6437E5} PluginSdkBinding diff --git a/src/keepass2android/packages.config b/src/keepass2android/packages.config index a965e39b..6f41db39 100644 --- a/src/keepass2android/packages.config +++ b/src/keepass2android/packages.config @@ -1,5 +1,6 @@  + @@ -28,7 +29,9 @@ + + @@ -54,6 +57,7 @@ +