switch to FluentFTP to close #825
This commit is contained in:
@@ -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<T>(Func<T> 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
|
||||
|
||||
@@ -141,10 +141,6 @@
|
||||
<Project>{70D3844A-D9FA-4A64-B205-A84C6A822196}</Project>
|
||||
<Name>KP2AKdbLibraryBinding</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\netftpandroid\System.Net.FtpClient\System.Net.FtpClient.Android.csproj">
|
||||
<Project>{146FD497-BA03-4740-B6C5-5C84EA8FCDE2}</Project>
|
||||
<Name>System.Net.FtpClient.Android</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\TwofishCipher\TwofishCipher.csproj">
|
||||
<Project>{5CF675A5-9BEE-4720-BED9-D5BF14A2EBF9}</Project>
|
||||
<Name>TwofishCipher</Name>
|
||||
@@ -157,6 +153,9 @@
|
||||
<None Include="app.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentFTP">
|
||||
<Version>27.1.3</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Graph">
|
||||
<Version>1.17.0</Version>
|
||||
</PackageReference>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -103,6 +103,9 @@
|
||||
</AndroidStoreUncompressedFileExtensions>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FluentFTP, Version=27.1.3.0, Culture=neutral, PublicKeyToken=f4af092b1d8df44f, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentFTP.27.1.3\lib\netstandard1.6\FluentFTP.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Java.Interop" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.Graph, Version=1.17.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
@@ -967,10 +970,6 @@
|
||||
<Project>{A8779D4D-7C49-4C2F-82BD-2CDC448391DA}</Project>
|
||||
<Name>Kp2aKeyboardBinding</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\netftpandroid\System.Net.FtpClient\System.Net.FtpClient.Android.csproj">
|
||||
<Project>{146FD497-BA03-4740-B6C5-5C84EA8FCDE2}</Project>
|
||||
<Name>System.Net.FtpClient.Android</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\PluginSdkBinding\PluginSdkBinding.csproj">
|
||||
<Project>{3DA3911E-36DE-465E-8F15-F1991B6437E5}</Project>
|
||||
<Name>PluginSdkBinding</Name>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="FluentFTP" version="27.1.3" targetFramework="monoandroid90" />
|
||||
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="MonoAndroid60" />
|
||||
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="MonoAndroid60" />
|
||||
<package id="Microsoft.Graph" version="1.17.0" targetFramework="monoandroid90" />
|
||||
@@ -28,7 +29,9 @@
|
||||
<package id="System.Linq" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.Net.Http" version="4.3.3" targetFramework="monoandroid90" />
|
||||
<package id="System.Net.NameResolution" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.Net.Primitives" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.Net.Security" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.Net.Sockets" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.ObjectModel" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.Private.Uri" version="4.3.2" targetFramework="monoandroid90" />
|
||||
@@ -54,6 +57,7 @@
|
||||
<package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.Threading" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.Threading.Thread" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.Threading.Timer" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.ValueTuple" version="4.3.0" targetFramework="monoandroid90" />
|
||||
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="monoandroid90" />
|
||||
|
||||
Reference in New Issue
Block a user