Update to latest FluentFTP version

This commit is contained in:
Rick Brown
2023-10-08 18:23:11 -04:00
parent c16eeff130
commit c8abb4d76a
2 changed files with 45 additions and 35 deletions

View File

@@ -1,18 +1,18 @@
#if !NoNet #if !NoNet
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Reflection;
using System.Threading;
using Android.Content; using Android.Content;
using Android.OS; using Android.OS;
using Android.Preferences;
using FluentFTP; using FluentFTP;
using FluentFTP.Exceptions;
using KeePassLib; using KeePassLib;
using KeePassLib.Serialization; using KeePassLib.Serialization;
using KeePassLib.Utility; using KeePassLib.Utility;
namespace keepass2android.Io namespace keepass2android.Io
{ {
public class NetFtpFileStorage: IFileStorage public class NetFtpFileStorage: IFileStorage
@@ -138,7 +138,7 @@ namespace keepass2android.Io
var settings = ConnectionSettings.FromIoc(ioc); var settings = ConnectionSettings.FromIoc(ioc);
FtpClient client = new FtpClient(); FtpClient client = new FtpClient();
client.RetryAttempts = 3; client.Config.RetryAttempts = 3;
if ((settings.Username.Length > 0) || (settings.Password.Length > 0)) if ((settings.Username.Length > 0) || (settings.Password.Length > 0))
client.Credentials = new NetworkCredential(settings.Username, settings.Password); client.Credentials = new NetworkCredential(settings.Username, settings.Password);
else else
@@ -154,7 +154,7 @@ namespace keepass2android.Io
args.Accept = _app.CertificateValidationCallback(control, args.Certificate, args.Chain, args.PolicyErrors); args.Accept = _app.CertificateValidationCallback(control, args.Certificate, args.Chain, args.PolicyErrors);
}; };
client.EncryptionMode = settings.EncryptionMode; client.Config.EncryptionMode = settings.EncryptionMode;
client.Connect(); client.Connect();
return client; return client;
@@ -284,42 +284,43 @@ namespace keepass2android.Io
public IEnumerable<FileDescription> ListContents(IOConnectionInfo ioc) public IEnumerable<FileDescription> ListContents(IOConnectionInfo ioc)
{ {
try try
{ {
using (var client = GetClient(ioc)) using (var client = GetClient(ioc))
{ {
List<FileDescription> files = new List<FileDescription>(); List<FileDescription> files = new List<FileDescription>();
foreach (FtpListItem item in client.GetListing(IocToLocalPath(ioc), foreach (FtpListItem item in client.GetListing(IocToLocalPath(ioc),
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() files.Add(new FileDescription()
{ {
CanRead = true, CanRead = true,
CanWrite = true, CanWrite = true,
DisplayName = item.Name, DisplayName = item.Name,
IsDirectory = true, IsDirectory = true,
LastModified = item.Modified, LastModified = item.Modified,
Path = IocPathFromUri(ioc, item.FullName) Path = IocPathFromUri(ioc, item.FullName)
}); });
break; break;
case FtpFileSystemObjectType.File: case FtpObjectType.File:
files.Add(new FileDescription() files.Add(new FileDescription()
{ {
CanRead = true, CanRead = true,
CanWrite = true, CanWrite = true,
DisplayName = item.Name, DisplayName = item.Name,
IsDirectory = false, IsDirectory = false,
LastModified = item.Modified, LastModified = item.Modified,
Path = IocPathFromUri(ioc, item.FullName), Path = IocPathFromUri(ioc, item.FullName),
SizeInBytes = item.Size SizeInBytes = item.Size
}); });
break;
default:
Kp2aLog.Log("FTP: ListContents item skipped: " + IocToUri(ioc) + ": " + item.FullName + ", type=" + item.Type);
break; break;
}
}
} }
return files; return files;
} }
@@ -329,7 +330,6 @@ namespace keepass2android.Io
throw ConvertException(ex); throw ConvertException(ex);
} }
} }
public FileDescription GetFileDescription(IOConnectionInfo ioc) public FileDescription GetFileDescription(IOConnectionInfo ioc)
{ {
@@ -466,7 +466,9 @@ namespace keepass2android.Io
public static int GetDefaultPort(FtpEncryptionMode encryption) 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) public string BuildFullPath(string host, int port, string initialPath, string user, string password, FtpEncryptionMode encryption)
@@ -582,5 +584,13 @@ namespace keepass2android.Io
_stream.Close(); _stream.Close();
} }
} }
class Kp2aLogFTPLogger : IFtpLogger
{
public void Log(FtpLogEntry entry)
{
Kp2aLog.Log("FluentFTP: " + entry.Message);
}
}
} }
#endif #endif

View File

@@ -182,7 +182,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(Flavor)'!='NoNet' "> <ItemGroup Condition=" '$(Flavor)'!='NoNet' ">
<PackageReference Include="FluentFTP"> <PackageReference Include="FluentFTP">
<Version>31.3.1</Version> <Version>48.0.0</Version>
</PackageReference> </PackageReference>
<PackageReference Include="MegaApiClient"> <PackageReference Include="MegaApiClient">
<Version>1.10.3</Version> <Version>1.10.3</Version>
@@ -312,4 +312,4 @@
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>