robinrodricks / fluentftp.gnutls Goto Github PK
View Code? Open in Web Editor NEWPremiere .NET wrapper for GnuTLS along with integration into FluentFTP
License: GNU Lesser General Public License v2.1
Premiere .NET wrapper for GnuTLS along with integration into FluentFTP
License: GNU Lesser General Public License v2.1
While attempting to debug connection issues I came across the following exception. After removing the progress parameter the exception isn't thrown.
var downloadProgress = new Progress<FtpProgress>(p =>
{
var progress = (int)p.Progress;
if (progress % 10 == 0)
{
_logger.LogInformation(
"Progress: {Progress:F1}% ETA: {Eta}",
p.Progress,
p.ETA);
}
});
var client = new AsyncFtpClient(host, username, password);
client.Config.CustomStream = typeof(GnuTlsStream);
await client.AutoConnect(cancellationToken).ConfigureAwait(false);
var downloadStatus = await client.DownloadFile(
fileDestinationPath,
normalizedFilePath,
verifyOptions: FtpVerify.OnlyChecksum | FtpVerify.Retry | FtpVerify.Delete,
progress: downloadProgress,
token: cancellationToken)
.ConfigureAwait(false);
Exception:
FluentFTP.Exceptions.FtpException: Error while downloading the file from the server. See InnerException for more info.
---> System.ArgumentException: GnuTlsInternalStream.Read: maxCount must be greater than zero
at FluentFTP.GnuTLS.GnuTlsInternalStream.Read(Byte[] buffer, Int32 offset, Int32 maxCount)
at System.IO.Stream.<>c.<BeginReadInternal>b__38_0(Object <p0>)
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at FluentFTP.FtpSocketStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken token)
at FluentFTP.FtpDataStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken token)
at FluentFTP.AsyncFtpClient.DownloadFileInternalAsync(String localPath, String remotePath, Stream outStream, Int64 restartPosition, IProgress`1 progress, CancellationToken token, FtpProgress metaProgress, Int64 knownFileSize, Boolean isAppend, Int64 stopPosition)
--- End of inner exception stack trace ---
at FluentFTP.AsyncFtpClient.DownloadFileInternalAsync(String localPath, String remotePath, Stream outStream, Int64 restartPosition, IProgress`1 progress, CancellationToken token, FtpProgress metaProgress, Int64 knownFileSize, Boolean isAppend, Int64 stopPosition)
at FluentFTP.AsyncFtpClient.DownloadFileToFileAsync(String localPath, String remotePath, FtpLocalExists existsMode, FtpVerify verifyOptions, IProgress`1 progress, CancellationToken token, FtpProgress metaProgress)
at FluentFTP.AsyncFtpClient.DownloadFile(String localPath, String remotePath, FtpLocalExists existsMode, FtpVerify verifyOptions, IProgress`1 progress, CancellationToken token)
I have problem with this connection.
On any operation i have error
FluentFTP.Exceptions.FtpCommandException: 'Code: 425 Message: Unable to build data connection: Operation not permitted'
var client = new FtpClient("ftp.gls-italy.com", item.user_ftp, item.pwd_ftp);
// connect to the server and automatically detect working FTP settings
client.Config.LogToConsole = true;
client.Config.EncryptionMode = FtpEncryptionMode.Auto;
client.Config.ValidateAnyCertificate = true;
client.Config.SslProtocols = SslProtocols.None;
client.Config.EncryptionMode = FtpEncryptionMode.Explicit;
client.Connect();
client.DownloadFile(@"C:\temp\Cassegni280220231529.txt", "Cassegni280220231529.txt");
# Connect(False)
Status: FluentFTP 45.2.0.0
Status: Connecting to IP #1= ***:21
Status: Waiting for a response
Response: 220 ProFTPD 1.3.5e Server (ftpB) [93.62.193.42] [738579,632d]
Status: Detected FTP server: ProFTPD
Command: AUTH TLS
Status: Waiting for response to: AUTH TLS
Response: 234 AUTH TLS successful [30ms]
Status: FTPS authentication successful, lib = .NET SslStream, cipher suite = Tls12 (Aes256, 44550, 256) [100ms]
Command: USER ***
Status: Waiting for response to: USER ***
Response: 331 Password required for *** [33ms]
Command: PASS ***
Status: Waiting for response to: PASS ***
Response: 230 User *** logged in. [60ms]
Command: PBSZ 0
Status: Waiting for response to: PBSZ 0
Response: 200 PBSZ 0 successful [32ms]
Command: PROT P
Status: Waiting for response to: PROT P
Response: 200 Protection set to Private [30ms]
Command: FEAT
Status: Waiting for response to: FEAT
Response: 211-Features:
Response: AUTH TLS
Response: MFF modify;UNIX.group;UNIX.mode;
Response: REST STREAM
Response: MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.mode*;UNIX.owner*;
Response: UTF8
Response: EPRT
Response: EPSV
Response: LANG zh-CN;zh-TW;bg-BG;en-US;es-ES;fr-FR;it-IT;ja-JP;ko-KR;ru-RU
Response: MDTM
Response: SSCN
Response: TVFS
Response: MFMT
Response: SIZE
Response: PROT
Response: CCC
Response: PBSZ
Response: 211 End [33ms]
Status: Text encoding: System.Text.UTF8Encoding
Command: OPTS UTF8 ON
Status: Waiting for response to: OPTS UTF8 ON
Response: 200 UTF8 set to on [29ms]
Command: SYST
Status: Waiting for response to: SYST
Response: 215 UNIX Type: L8 [29ms]
Status: Listing parser set to: Machine
Command: PWD
Status: Waiting for response to: PWD
Response: 257 "/" is the current directory [28ms]
# DownloadFile("C:\temp\Cassegni280220231529.txt", "Cassegni280220231529.txt", Overwrite, None)
# OpenRead("Cassegni280220231529.txt", Binary, 0, 0)
# GetFileSize("Cassegni280220231529.txt")
Command: SIZE Cassegni280220231529.txt
Status: Waiting for response to: SIZE Cassegni280220231529.txt
Response: 550 SIZE not allowed in ASCII mode [28ms]
Command: TYPE I
Status: Waiting for response to: TYPE I
Response: 200 Type set to I [31ms]
Command: SIZE Cassegni280220231529.txt
Status: Waiting for response to: SIZE Cassegni280220231529.txt
Response: 213 19272 [32ms]
# OpenDataStream("RETR Cassegni280220231529.txt", 0)
# OpenPassiveDataStream(AutoPassive, "RETR Cassegni280220231529.txt", 0)
Command: EPSV
Status: Waiting for response to: EPSV
Response: 229 Entering Extended Passive Mode (|||64917|) [30ms]
Status: Connecting to IP #1= ***:64917
Command: RETR Cassegni280220231529.txt
Status: Waiting for response to: RETR Cassegni280220231529.txt
Response: 150 Opening BINARY mode data connection for Cassegni280220231529.txt (19272 bytes) [30ms]
Status: FTPS authentication successful, lib = .NET SslStream, cipher suite = Tls12 (Aes256, 44550, 256) [49ms]
Status: Downloaded 0 bytes
Status: Closing/Disposing FtpSocketStream(data connection)
Status: Waiting for response to: *DOWNLOAD*
Response: 425 Unable to build data connection: Operation not permitted [89ms]
Status: Failed to download file.
# GetListing("/", Auto)
# OpenDataStream("MLSD /", 0)
Status: Testing connectivity using Socket.Poll()...
# OpenPassiveDataStream(AutoPassive, "MLSD /", 0)
Command: EPSV
Status: Waiting for response to: EPSV
Response: 229 Entering Extended Passive Mode (|||59012|) [34ms]
Status: Connecting to IP #1= ***:59012
Command: MLSD /
Status: Waiting for response to: MLSD /
Response: 150 Opening BINARY mode data connection for MLSD [29ms]
Status: FTPS authentication successful, lib = .NET SslStream, cipher suite = Tls12 (Aes256, 44550, 256) [56ms]
+---------------------------------------+
-----------------------------------------
Status: Closing/Disposing FtpSocketStream(data connection)
# CloseDataStream()
Status: Waiting for response to: MLSD /
Response: 425 Unable to build data connection: Operation not permitted [89ms]
Status: Closing/Disposing FtpSocketStream(data connection)
@FanDjango
Unfortunately looking at the logs of my test app, the polling loop that's being executed on a schedule now suddenly started throwing a different error over the "module could not be found" one after I loaded the DLLs in a sequence.
New error:
'FluentFTP.GnuTLS.GnuTlsException: Error : *GnuTlsCertificateSetX509SystemTrust(...) failed: (-64) GNUTLS_E_FILE_ERROR
at FluentFTP.GnuTLS.Core.GnuUtils.Check(String methodName, Int32 result, Int32[] resultsAllowed)
at FluentFTP.GnuTLS.GnuTlsInternalStream..ctor(String targetHostString, Socket socketDescriptor, CustomRemoteCertificateValidationCallback customRemoteCertificateValidation, X509CertificateCollection clientCertificates, String alpnString, GnuTlsInternalStream streamToResumeFrom, String priorityString, Boolean deInitGnuTls, String loadLibraryDllNamePrefix, Int32 handshakeTimeout, Int32 pollTimeout, GnuStreamLogCBFunc elog, Int32 logMaxLevel, GnuMessage logDebugInformationMessages, Int32 logQueueMaxSize)
at FluentFTP.GnuTLS.GnuTlsStream.Init(BaseFtpClient client, String targetHost, Socket socket, CustomRemoteCertificateValidationCallback customRemoteCertificateValidation, Boolean isControl, IFtpStream controlConnStream, IFtpStreamConfig untypedConfig)
at FluentFTP.FtpSocketStream.CreateCustomStream(String targetHost)
at FluentFTP.FtpSocketStream.ActivateEncryptionAsync(String targetHost, X509CertificateCollection clientCerts, SslProtocols sslProtocols, CancellationToken token)
at FluentFTP.AsyncFtpClient.Connect(Boolean reConnect, CancellationToken token)
at FluentFTP.AsyncFtpClient.Connect(CancellationToken token)
It never ends does it? ๐ Any clue what this one means/how it can be fixed? Or could it be because I now loaded the DLLs concurrently with the polling logic, where it would normally be executed beforehand and thus be nothing to worry about? (not me being naive/hopeful)
Originally posted by @rob-hendrickx-c4t in #76 (comment)
Hi,
I tried to use FluentFTP.GnuTLS to connect with FileZilla v1.7.2 but failed.
In my .Net code, I include the following references:
PackageReference Include="FluentFTP" Version="47.1.0" />
PackageReference Include="FluentFTP.GnuTLS" Version="1.0.22" />
And then I use the example function ConnectFTPSCertificate in https://github.com/robinrodricks/FluentFTP.GnuTLS/blob/master/FluentFTP.CSharpExamples/ConnectFTPSGnuTLS.cs
After conn.Connect(), the excetpion is thrown:
*GnuTlsHandShake(...) failed: (-110) GNUTLS_E_PREMATURE_TERMINATION
The log on FileZilla is:
<30-08-2023 15:35:04> FTP Session 44 192.168.100.223 [Response] 220-FileZilla Server 1.7.2
<30-08-2023 15:35:04> FTP Session 44 192.168.100.223 [Response] 220 Please visit https://filezilla-project.org/
<30-08-2023 15:35:04> FTP Session 44 192.168.100.223 [Command] AUTH TLS
<30-08-2023 15:35:04> FTP Session 44 192.168.100.223 [Response] 234 Using authentication type TLS.
<30-08-2023 15:35:04> FTP Session 44 192.168.100.223 [Error] GnuTLS error -344: No common application protocol could be negotiated.
<30-08-2023 15:35:04> FTP Session 44 192.168.100.223 [Error] Control channel closed with error from source 0. Reason: ECONNABORTED - Connection aborted.
Do I miss any settings or components? Thanks.
System: Windows 10. I have Not tested this under linux.
Current FluentFTP.GnuTLS 1.0.21
The following code fails consistently (on my machine) after exactly 533 iterations:
static void My_Loop_Test() {
using (var client = new FtpClient("127.0.0.1", "mike", "7u8i9o0p")) {
client.Config.EncryptionMode = FtpEncryptionMode.Explicit;
client.Config.SslProtocols = SslProtocols.None;
client.Config.DataConnectionType = FtpDataConnectionType.PASV;
client.Config.DownloadDataType = FtpDataType.Binary;
client.Config.ValidateAnyCertificate = true;
client.Config.SslSessionLength = 0;
client.Config.CustomStream = typeof(GnuTlsStream);
client.Config.CustomStreamConfig = new GnuConfig() {
SetALPNControlConnection = string.Empty,
SetALPNDataConnection = string.Empty,
DllUnloadByUseCount = true,
LogLevel = 0,
LogMessages = GnuMessage.None,
};
for (int i = 0; i < 999999; i++) {
Console.WriteLine(i.ToString());
client.Connect();
client.Disconnect();
}
}
}
What is the failure: No message, no indication in the log, nothing. Process terminates with code 3.
532
533
C:\Users\M....\Test_FluentZOS_Net_6.exe (process 30784) exited with code 3.
If I change the DllUnloadByUseCount
to false
, there is no failure, even after many many load-unloads.
I will start investigating this.
@fredericDelaporte This is what is happening to you, I think.
Trying to use multiple AsyncFtpClient
instances results in an access violation:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at FluentFTP.GnuTLS.GnuTlsInternalStream.Dispose()
at FluentFTP.GnuTLS.GnuTlsStream.Dispose()
at FluentFTP.FtpSocketStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at FluentFTP.Client.BaseClient.BaseFtpClient.Dispose()
at FluentFTP.Client.BaseClient.BaseFtpClient.Finalize()
private static async Task TestFtp()
{
FluentFTP.AsyncFtpClient client = new FluentFTP.AsyncFtpClient("127.0.0.1", 21, new FluentFTP.FtpConfig()
{
DataConnectionType = FluentFTP.FtpDataConnectionType.AutoPassive,
EncryptionMode = FluentFTP.FtpEncryptionMode.Explicit,
SslProtocols = System.Security.Authentication.SslProtocols.Tls12,
CustomStream = typeof(GnuTlsStream),
CustomStreamConfig = new GnuConfig()
{
SecuritySuite = FluentFTP.GnuTLS.Enums.GnuSuite.Secure128,
SetALPNControlConnection = string.Empty,
SetALPNDataConnection = string.Empty
}
})
{
Credentials = new System.Net.NetworkCredential("user", "asdf")
};
client.ValidateCertificate += (BaseFtpClient control, FtpSslValidationEventArgs e) => { e.Accept = true; };
var listing = await client.GetListing("/temp");
foreach (var item in listing)
{
Console.WriteLine(item.FullName);
}
}
public static int Main(string[] args)
{
var t1 = Task.Run(TestFtp);
var t2 = Task.Run(TestFtp);
t1.Wait();
t2.Wait();
return 0;
}
Connecting to FileZilla Server version 1.7.2.
If I comment out t2, there is no exception. Both list tasks print all of the files before crashing, it seems like a resource is shared and deleted twice.
Post these under FluentFTP: https://github.com/robinrodricks/FluentFTP/issues
FluentFTP.GnuTLS is great but do not load when using .Net6 project under Linux:
FTPS Authentication failed, lib = FluentFTP.GnuTLS.GnuTlsStream : FluentFTP.GnuTLS.GnuTlsException: GnuTLS .dll load/call validation error ---> System.DllNotFoundException: Unable to load shared library 'libgnutls-30.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibgnutls-30.dll: cannot open shared object file: No such file or directory
Actually, on linux libgnutls-30 exist as /usr/lib64/libgnutls.so.30
Is there a chance to have a updated package that also support Linux ?
Whenever I try to use FluentFTP with GnuTLS enabled locally in an Azure Function, everything works as expected.
When deploying the function app to Azure on a Windows plan however, I bump into the following error:
FluentFTP.GnuTLS.GnuTlsException: Could not load libgnutls-30.dll, (126) The specified module could not be found.
Even though the libgnutls-30.dll file is located in the same folder as the dll of my function app. I don't know how the DLL loading logic of GnuTLS works, but I think I might have encountered a similar issue in the past already.
Azure Functions running on Azure seem to be running from a different location from where the DLL is in fact located. This lead to the problem that e.g. Environment.CurrentDirectory points to a location like D:\Program Files (x86)\SiteExtensions\Functions\2.0.12493\64bit
instead of C:\home\site\wwwroot\bin
where my own binaries would be stored.
Therefor I am wondering if it is possible to add support to do either of the following:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.