Merge pull request #2435 from hyproman/upgrade-fluentftp
Update to latest FluentFTP version
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
#if !NoNet
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Preferences;
|
||||
using FluentFTP;
|
||||
using FluentFTP.Exceptions;
|
||||
using KeePassLib;
|
||||
using KeePassLib.Serialization;
|
||||
using KeePassLib.Utility;
|
||||
|
||||
|
||||
namespace keepass2android.Io
|
||||
{
|
||||
public class NetFtpFileStorage: IFileStorage
|
||||
@@ -75,14 +75,15 @@ namespace keepass2android.Io
|
||||
}
|
||||
|
||||
private readonly ICertificateValidationHandler _app;
|
||||
private readonly Func<bool> _debugLogPrefGetter;
|
||||
|
||||
public MemoryStream traceStream;
|
||||
|
||||
public NetFtpFileStorage(Context context, ICertificateValidationHandler app)
|
||||
public NetFtpFileStorage(Context context, ICertificateValidationHandler app, Func<bool> debugLogPrefGetter)
|
||||
{
|
||||
_app = app;
|
||||
traceStream = new MemoryStream();
|
||||
|
||||
_debugLogPrefGetter = debugLogPrefGetter;
|
||||
traceStream = new MemoryStream();
|
||||
}
|
||||
|
||||
public IEnumerable<string> SupportedProtocols
|
||||
@@ -138,7 +139,7 @@ namespace keepass2android.Io
|
||||
var settings = ConnectionSettings.FromIoc(ioc);
|
||||
|
||||
FtpClient client = new FtpClient();
|
||||
client.RetryAttempts = 3;
|
||||
client.Config.RetryAttempts = 3;
|
||||
if ((settings.Username.Length > 0) || (settings.Password.Length > 0))
|
||||
client.Credentials = new NetworkCredential(settings.Username, settings.Password);
|
||||
else
|
||||
@@ -154,9 +155,12 @@ namespace keepass2android.Io
|
||||
args.Accept = _app.CertificateValidationCallback(control, args.Certificate, args.Chain, args.PolicyErrors);
|
||||
};
|
||||
|
||||
client.EncryptionMode = settings.EncryptionMode;
|
||||
|
||||
client.Connect();
|
||||
client.Config.EncryptionMode = settings.EncryptionMode;
|
||||
|
||||
if (_debugLogPrefGetter())
|
||||
client.Logger = new Kp2aLogFTPLogger();
|
||||
|
||||
client.Connect();
|
||||
return client;
|
||||
|
||||
}
|
||||
@@ -284,7 +288,7 @@ namespace keepass2android.Io
|
||||
|
||||
public IEnumerable<FileDescription> ListContents(IOConnectionInfo ioc)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
using (var client = GetClient(ioc))
|
||||
{
|
||||
@@ -302,36 +306,37 @@ namespace keepass2android.Io
|
||||
|
||||
List<FileDescription> files = new List<FileDescription>();
|
||||
foreach (FtpListItem item in client.GetListing(null,
|
||||
FtpListOption.Modify | FtpListOption.Size | FtpListOption.DerefLinks))
|
||||
FtpListOption.SizeModify | FtpListOption.AllFiles))
|
||||
{
|
||||
|
||||
switch (item.Type)
|
||||
switch (item.Type)
|
||||
{
|
||||
case FtpFileSystemObjectType.Directory:
|
||||
case FtpObjectType.Directory:
|
||||
files.Add(new FileDescription()
|
||||
{
|
||||
CanRead = true,
|
||||
CanWrite = true,
|
||||
DisplayName = item.Name,
|
||||
IsDirectory = true,
|
||||
LastModified = item.Modified,
|
||||
Path = IocPathFromUri(ioc, item.FullName)
|
||||
});
|
||||
break;
|
||||
case FtpFileSystemObjectType.File:
|
||||
{
|
||||
CanRead = true,
|
||||
CanWrite = true,
|
||||
DisplayName = item.Name,
|
||||
IsDirectory = true,
|
||||
LastModified = item.Modified,
|
||||
Path = IocPathFromUri(ioc, item.FullName)
|
||||
});
|
||||
break;
|
||||
case FtpObjectType.File:
|
||||
files.Add(new FileDescription()
|
||||
{
|
||||
CanRead = true,
|
||||
CanWrite = true,
|
||||
DisplayName = item.Name,
|
||||
IsDirectory = false,
|
||||
LastModified = item.Modified,
|
||||
Path = IocPathFromUri(ioc, item.FullName),
|
||||
SizeInBytes = item.Size
|
||||
});
|
||||
{
|
||||
CanRead = true,
|
||||
CanWrite = true,
|
||||
DisplayName = item.Name,
|
||||
IsDirectory = false,
|
||||
LastModified = item.Modified,
|
||||
Path = IocPathFromUri(ioc, item.FullName),
|
||||
SizeInBytes = item.Size
|
||||
});
|
||||
break;
|
||||
default:
|
||||
Kp2aLog.Log("FTP: ListContents item skipped: " + IocToUri(ioc) + ": " + item.FullName + ", type=" + item.Type);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
@@ -341,7 +346,6 @@ namespace keepass2android.Io
|
||||
throw ConvertException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public FileDescription GetFileDescription(IOConnectionInfo ioc)
|
||||
{
|
||||
@@ -478,7 +482,9 @@ namespace keepass2android.Io
|
||||
|
||||
public static int GetDefaultPort(FtpEncryptionMode encryption)
|
||||
{
|
||||
return new FtpClient() { EncryptionMode = encryption}.Port;
|
||||
var client = new FtpClient();
|
||||
client.Config.EncryptionMode = encryption;
|
||||
return client.Port;
|
||||
}
|
||||
|
||||
public string BuildFullPath(string host, int port, string initialPath, string user, string password, FtpEncryptionMode encryption)
|
||||
@@ -594,5 +600,13 @@ namespace keepass2android.Io
|
||||
_stream.Close();
|
||||
}
|
||||
}
|
||||
|
||||
class Kp2aLogFTPLogger : IFtpLogger
|
||||
{
|
||||
public void Log(FtpLogEntry entry)
|
||||
{
|
||||
Kp2aLog.Log("[FluentFTP] " + entry.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -182,7 +182,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Flavor)'!='NoNet' ">
|
||||
<PackageReference Include="FluentFTP">
|
||||
<Version>31.3.1</Version>
|
||||
<Version>48.0.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MegaApiClient">
|
||||
<Version>1.10.3</Version>
|
||||
@@ -312,4 +312,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
@@ -391,8 +391,8 @@ namespace keepass2android
|
||||
string user = dlgContents.FindViewById<EditText>(Resource.Id.ftp_user).Text;
|
||||
string password = dlgContents.FindViewById<EditText>(Resource.Id.ftp_password).Text;
|
||||
string initialPath = dlgContents.FindViewById<EditText>(Resource.Id.ftp_initial_dir).Text;
|
||||
string ftpPath = new NetFtpFileStorage(_activity, App.Kp2a).BuildFullPath(host, port, initialPath, user,
|
||||
password, encryption);
|
||||
string ftpPath = new NetFtpFileStorage(_activity, App.Kp2a, () => false)
|
||||
.BuildFullPath(host, port, initialPath, user, password, encryption);
|
||||
onStartBrowse(ftpPath);
|
||||
});
|
||||
EventHandler<DialogClickEventArgs> evtH = new EventHandler<DialogClickEventArgs>((sender, e) => onCancel());
|
||||
|
@@ -98,7 +98,7 @@
|
||||
<string name="TrayTotp_SeedField_key">TrayTotp_SeedField_key</string>
|
||||
<string name="TrayTotp_prefs_key">TrayTotp_prefs_key</string>
|
||||
<string name="DebugLog_key">DebugLog_key</string>
|
||||
<string name="JSchDebug_key">JSchDebug_key</string>
|
||||
<string name="FtpDebug_key">FtpDebug_key</string>
|
||||
<string name="DebugLog_prefs_key">DebugLog_prefs_key</string>
|
||||
<string name="DebugLog_send_key">DebugLog_send</string>
|
||||
<string name="AutofillDisabledQueriesPreference_key">AutofillDisabledQueriesPreference_key</string>
|
||||
@@ -216,4 +216,4 @@
|
||||
|
||||
<string name="ClearPasswordOnLeave_key">ClearPasswordOnLeave</string>
|
||||
|
||||
</resources>
|
||||
</resources>
|
||||
|
@@ -704,7 +704,7 @@
|
||||
<string name="TrayTotp_prefs">TrayTotp</string>
|
||||
<string name="DebugLog_prefs_prefs">Log-File for Debugging</string>
|
||||
<string name="DebugLog_title">Use log file</string>
|
||||
<string name="JSchDebug_title">SFTP debug logging</string>
|
||||
<string name="FtpDebug_title">FTP/SFTP debug logging</string>
|
||||
<string name="DebugLog_summary">Write app output to a local log file</string>
|
||||
<string name="DebugLog_send">Send debug log...</string>
|
||||
|
||||
|
@@ -677,10 +677,10 @@
|
||||
android:key="@string/DebugLog_send_key" />
|
||||
<CheckBoxPreference
|
||||
android:enabled="true"
|
||||
android:persistent="false"
|
||||
android:persistent="true"
|
||||
android:defaultValue="false"
|
||||
android:title="@string/JSchDebug_title"
|
||||
android:key="@string/JSchDebug_key" />
|
||||
android:title="@string/FtpDebug_title"
|
||||
android:key="@string/FtpDebug_key" />
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
||||
|
||||
|
@@ -833,7 +833,7 @@ namespace keepass2android
|
||||
new OneDrive2MyFilesFileStorage(),
|
||||
new OneDrive2AppFolderFileStorage(),
|
||||
new SftpFileStorage(LocaleManager.LocalizedAppContext, this),
|
||||
new NetFtpFileStorage(LocaleManager.LocalizedAppContext, this),
|
||||
new NetFtpFileStorage(LocaleManager.LocalizedAppContext, this, IsFtpDebugEnabled),
|
||||
new WebDavFileStorage(this),
|
||||
new PCloudFileStorage(LocaleManager.LocalizedAppContext, this),
|
||||
new PCloudFileStorageAll(LocaleManager.LocalizedAppContext, this),
|
||||
@@ -849,6 +849,12 @@ namespace keepass2android
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsFtpDebugEnabled()
|
||||
{
|
||||
return PreferenceManager.GetDefaultSharedPreferences(LocaleManager.LocalizedAppContext)
|
||||
.GetBoolean(LocaleManager.LocalizedAppContext.GetString(Resource.String.FtpDebug_key), false);
|
||||
}
|
||||
|
||||
public void TriggerReload(Context ctx, Action<bool> actionOnResult)
|
||||
{
|
||||
Handler handler = new Handler(Looper.MainLooper);
|
||||
|
@@ -179,9 +179,9 @@ namespace keepass2android
|
||||
FindPreference(GetString(Resource.String.DebugLog_send_key)).PreferenceClick += OnSendDebug;
|
||||
|
||||
#if !EXCLUDE_JAVAFILESTORAGE && !NoNet
|
||||
FindPreference(GetString(Resource.String.JSchDebug_key)).PreferenceChange += OnJSchDebugChanged;
|
||||
FindPreference(GetString(Resource.String.FtpDebug_key)).PreferenceChange += OnJSchDebugChanged;
|
||||
#else
|
||||
FindPreference(GetString(Resource.String.JSchDebug_key)).Enabled = false;
|
||||
FindPreference(GetString(Resource.String.FtpDebug_key)).Enabled = false;
|
||||
#endif
|
||||
|
||||
HashSet<string> supportedLocales = new HashSet<string>() { "en", "af", "ar", "az", "be", "bg", "ca", "cs", "da", "de", "el", "es", "eu", "fa", "fi", "fr", "gl", "he", "hr", "hu", "id", "in", "it", "iw", "ja", "ko", "ml", "nb", "nl", "nn", "no", "pl", "pt", "ro", "ru", "si", "sk", "sl", "sr", "sv", "tr", "uk", "vi", "zh" };
|
||||
@@ -393,9 +393,8 @@ namespace keepass2android
|
||||
Kp2aLog.FinishLogFile();
|
||||
|
||||
#if !EXCLUDE_JAVAFILESTORAGE && !NoNet
|
||||
bool jschLogEnable = PreferenceManager.GetDefaultSharedPreferences(Application.Context)
|
||||
.GetBoolean(Application.Context.GetString(Resource.String.JSchDebug_key), false);
|
||||
SetJSchLogging(jschLogEnable);
|
||||
SetJSchLogging(PreferenceManager.GetDefaultSharedPreferences(Application.Context)
|
||||
.GetBoolean(Application.Context.GetString(Resource.String.FtpDebug_key), false));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -415,6 +414,7 @@ namespace keepass2android
|
||||
}
|
||||
sftpStorage.SetJschLogging(enabled, logFilename);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
private void AlgorithmPrefChange(object sender, Preference.PreferenceChangeEventArgs preferenceChangeEventArgs)
|
||||
|
Reference in New Issue
Block a user