FluentFTP icon indicating copy to clipboard operation
FluentFTP copied to clipboard

Connection attempt hangs when network is unavailable

Open MarkBlaise opened this issue 7 months ago • 25 comments

FTP Server OS: Windows 2016 / 2019 - IIS 10.0 FTP Server Type: Unknown FluentFTP Version: FluentFTP 54.1.1.0(.NET 8.0+) Client Computer OS: Windows 11 VS 2022 17.14.31 (April 2026) Framework: .NET 9, Maui App Target: Android 15, both emulator and phone device (Galaxy S25)

Android app runs well when there is a network connection. As a test on the Android emulator, I turned off my computer's WiFi and the AutoConnect method for an async client seems to hang indefinitely. On the Android phone, the same happens when I turn off both WiFi and cellular data.

My code is pretty simple:

        private FtpProfile _prof = null;

        internal async Task<AsyncFtpClient> GetAsyncFtpClient(
            string host, 
            CancellationToken token, 
            NetworkCredential creds = null)
        {
            
            creds ??= GetNetworkCreds();
            AsyncFtpClient client = new(host, creds);
            client.Config.ValidateAnyCertificate = true;
            client.Config.ConnectTimeout = 15000;

            if (_prof == null)
                _prof = await client.AutoConnect(token);
            else
                await client.Connect(_prof, token);

            return client;
        }

With logging to the console I get the following when a network is present. Note that entries prefixed with [0:] are written by my code; entries made by FluentFtp appear to have a prefix of [DOTNET]. I have removed irrelevant console entries. I can provide the complete console output if desired.

Network present - Successful:

[0:] GetAsyncFtpClient entered
[0:] GetAsyncFtpClient calling AutoConnect
[DOTNET]
[DOTNET] # AutoConnect()
[DOTNET]
[DOTNET] # AutoDetect(CloneConnection = False, FirstOnly = True, IncludeImplicit = True, AbortOnTimeout = True, RequireEncryption = False, ProtocolPriority = [Tls12])
[DOTNET] Status:   Auto-Detect trying encryption mode "Auto" with protocol "Tls12"
[DOTNET]
[DOTNET] # Connect(False)
[0:] 20260428-21:23:35.976: SplashPage ctor exiting
[DOTNET] Status:   FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
[0:] 20260428-21:23:36.128: App OnStart entered
[DOTNET] Status:   Connecting(async) AsyncFtpClient.FtpSocketStream(control) IP #1 = ***:21
[DOTNET] Status:   Waiting for a response
[DOTNET] Response: 220-Microsoft FTP Service
[DOTNET] Response: 220 DiscountASP.NET FTP [739734.058d]
[DOTNET] Status:   Detected FTP server: WindowsServerIIS
[DOTNET] Command:  AUTH TLS
[DOTNET] Status:   Waiting for response to: AUTH TLS
[DOTNET] Response: 234 AUTH command ok. Expecting TLS Negotiation. [84ms]
[DOTNET] Status:   FTPS authentication successful, lib = .NET SslStream, cipher suite = Tls12 (Aes256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, DiffieHellman, 0) [941ms]
[DOTNET] Command:  USER ***
[DOTNET] Status:   Waiting for response to: USER ***
[DOTNET] Response: 331 Password required [86ms]
[DOTNET] Command:  PASS ***
[DOTNET] Status:   Waiting for response to: PASS ***
[DOTNET] Response: 230-Welcome to DiscountASP.NET
[DOTNET] Response: 230 User logged in. [100ms]
[DOTNET] Command:  PBSZ 0
[DOTNET] Status:   Waiting for response to: PBSZ 0
[DOTNET] Response: 200 PBSZ command successful. [82ms]
[DOTNET] Command:  PROT P
[DOTNET] Status:   Waiting for response to: PROT P
[DOTNET] Response: 200 PROT command successful. [82ms]
[DOTNET] Command:  FEAT
[DOTNET] Status:   Waiting for response to: FEAT
[DOTNET] Response: 211-Extended features supported:
[DOTNET] Response: LANG EN*
[DOTNET] Response: UTF8
[DOTNET] Response: AUTH TLS;TLS-C;SSL;TLS-P;
[DOTNET] Response: PBSZ
[DOTNET] Response: PROT C;P;
[DOTNET] Response: CCC
[DOTNET] Response: HOST
[DOTNET] Response: SIZE
[DOTNET] Response: MDTM
[DOTNET] Response: REST STREAM
[DOTNET] Response: 211 END [90ms]
[DOTNET] Status:   Text encoding: System.Text.UTF8Encoding+UTF8EncodingSealed
[DOTNET] Command:  OPTS UTF8 ON
[DOTNET] Status:   Waiting for response to: OPTS UTF8 ON
[DOTNET] Response: 200 OPTS UTF8 command successful - UTF8 encoding now ON. [82ms]
[DOTNET] Command:  SYST
[DOTNET] Status:   Waiting for response to: SYST
[DOTNET] Response: 215 Windows_NT [84ms]
[DOTNET] Status:   Active ServerHandler is: WindowsServerIIS
[DOTNET] Status:   Listing parser set to: Windows
[DOTNET] Command:  PWD
[DOTNET] Status:   Waiting for response to: PWD
[DOTNET] Response: 257 "/" is current directory. [84ms]
[0:] GetAsyncFtpClient AutoConnect returned
[0:] GetAsyncFtpClient exiting

No Network - Connection Hangs


[0:] GetAsyncFtpClient entered
[0:] GetAsyncFtpClient calling AutoConnect
[DOTNET]
[DOTNET] # AutoConnect()
[DOTNET]
[DOTNET] # AutoDetect(CloneConnection = False, FirstOnly = True, IncludeImplicit = True, AbortOnTimeout = True, RequireEncryption = False, ProtocolPriority = [Tls12])
[DOTNET] Status:   Auto-Detect trying encryption mode "Auto" with protocol "Tls12"
[0:] 20260428-21:24:54.158: SplashPage ctor exiting
[DOTNET]
[DOTNET] # Connect(False)
[DOTNET] Status:   FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
[DOTNET] Status:   Connecting(async) AsyncFtpClient.FtpSocketStream(control) IP #1 = ***:21
[0:] 20260428-21:24:54.279: App OnStart entered
[DOTNET]
[DOTNET] # Disconnect()
[DOTNET] Status:   Connection already closed, nothing to do.

I have tried the Connect method as well - also hangs. I've tried it with no parameters, and with a profile generated by AutoConnect when a network is present.

I concede that I may be doing something wrong or foolish, but I just don't see what that might be. Any help would be appreciated.

MarkBlaise avatar Apr 29 '26 13:04 MarkBlaise

There is a small amount of network specific things happening immediately after that last message:

check dns (BTW: did you supply an IP adress or a host name) Please try with a host name, it should fail immediately. create socket bind socket to local ip/port connect with timeout

I would need to add some more log messages for these steps.

FanDjango avatar Apr 29 '26 21:04 FanDjango

Hello and thank you for your response.

As for host name, I have always used a host name, never an ip.

As for timeout, I thought I was configuring the connection with a timeout ... does the code I showed above not do that?

Sorry, but I'm not sure what you mean by "create socket" and "bind socket to local ip/port". Are these things you expect to see happening, or are they things I should try?.

I'm an "old timer" and a bit out of my element, but if you give me explicit instructions, I'll carry them out and get whatever data is needed.

Thanks again.

MarkBlaise avatar Apr 30 '26 02:04 MarkBlaise

Sorry. I meant to say that those steps in our code have no log messages on them - they either work, or they fail with an exception. They don't hang indefinitely. Until now, that is.

So I am thinking that to diagnose this we need to find out where it is hanging. I should make a branch in my forked repo of FluentFTP that contains such diag log messages and ask you to perhaps use that.

Failing that I might put together a small .NET MAUI App and test this myself, although I am a bit of a beginner with MAUI. You say that it also happens with the emulator? So I would try that first.

FanDjango avatar Apr 30 '26 09:04 FanDjango

As for host name, I have always used a host name, never an ip

Great. Because in that case I might be able locate the place where something goes wrong by deduction.

Host Name: Needs a dns lookup.

[DOTNET] Status:   FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
[DOTNET] Status:   Connecting(async) AsyncFtpClient.FtpSocketStream(control) IP #1 = ***:21

How could it have succeeded with no network? Cached? Probably.

But you could do a confirmation test for me before I test further. Restart everything but do not test the connection, disable the network (wlan), and then try the connect. Should fail with an exception on the dns query.

Just to see if my reasoning is right.

Meanwhile I am putting together a small MAUI app to try to reproduce this.

FanDjango avatar Apr 30 '26 10:04 FanDjango

Okay. To confirm, I should turn off WiFi and reboot the machine, start the project in VS and see what happens, with logging to the console turned on? That's probably better than flushing the dns cache, etc. Is that what you had in mind?

Does client.Config.ConnectTimeout = 15000; establish a connection timeout on the ftp client, or is there something else I need to do?

Thank you.

MarkBlaise avatar Apr 30 '26 11:04 MarkBlaise

Okay. To confirm

I suppose flushing the dns cache would also work. I kind of forgot you could do that.

Does...

Yes. That value sets a timeout. But: you said it "hangs indefinitely". So that timeout is sadly not working and I don't know how far the connect progress has progressed along the sequence I mentioned, as there are no log messages indicating how far we are gettting. Typically, we rely on them to throw an exception. I mean, those are (in the end) internal methods of .NET - they shouldn't hang, right?

I am not progressing well, putting together a small MAUI app to test this - single stepping and logging is a hurdle for me right now - and simulating a disabled wifi. I am only an egg concerning mobile app development.

I'd prefer adding log messages into a new branch of my fork of the master FluentFTP and asking you to use that and report back how it progresses.

FanDjango avatar Apr 30 '26 11:04 FanDjango

Hi, sorry, I was stuck in a meeting for a while. SO, I turned off the WiFi, rebooted the machine, opened my project in Visual Studio and ran the app on an Android emulator with logging to a file and the console.

The first time I did this the app simply crashed. Here's the log file output:

2026-04-30 08:53:54.948 -04:00 [INF] GetAsyncFtpClient start
2026-04-30 08:53:54.975 -04:00 [INF] GetAsyncFtpClient calling AutoConnect
2026-04-30 08:53:54.977 -04:00 [INF] >         AutoConnect()
2026-04-30 08:53:54.986 -04:00 [INF] >         AutoDetect(CloneConnection = False, FirstOnly = True, IncludeImplicit = True, AbortOnTimeout = True, RequireEncryption = False, ProtocolPriority = [Tls12])
2026-04-30 08:53:55.003 -04:00 [DBG] Auto-Detect trying encryption mode "Auto" with protocol "Tls12"
2026-04-30 08:53:55.005 -04:00 [INF] >         Connect(False)
2026-04-30 08:53:55.006 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient

That was unexpected, but emulators can sometimes be a bit flaky, so I ran it again, and it didn't crash AND it didn't hang. It did not throw an exception either, AutoConnect returned with the client unconnected. My code threw exceptions trying to use that connection, but that is fair and my code handled it properly.

Here is the log file content for this run:

2026-04-30 08:55:31.189 -04:00 [INF] GetAsyncFtpClient start
2026-04-30 08:55:31.219 -04:00 [INF] GetAsyncFtpClient calling AutoConnect
2026-04-30 08:55:31.224 -04:00 [INF] >         AutoConnect()
2026-04-30 08:55:31.244 -04:00 [INF] >         AutoDetect(CloneConnection = False, FirstOnly = True, IncludeImplicit = True, AbortOnTimeout = True, RequireEncryption = False, ProtocolPriority = [Tls12])
2026-04-30 08:55:31.249 -04:00 [DBG] Auto-Detect trying encryption mode "Auto" with protocol "Tls12"
2026-04-30 08:55:31.253 -04:00 [INF] >         Connect(False)
2026-04-30 08:55:31.256 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 08:55:51.364 -04:00 [INF] >         Disconnect()
2026-04-30 08:55:51.365 -04:00 [DBG] Connection already closed, nothing to do.
2026-04-30 08:55:59.961 -04:00 [INF] >         DirectoryExists("/Family-Files/CryptoVault")
2026-04-30 08:55:59.970 -04:00 [WRN] Reconnect needed due to disconnected control connection
2026-04-30 08:55:59.970 -04:00 [INF] Command stashed: PWD
2026-04-30 08:55:59.971 -04:00 [INF] >         Connect(True)
2026-04-30 08:55:59.972 -04:00 [WRN] Reconnect (Count: 1)
2026-04-30 08:55:59.973 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 08:56:20.188 -04:00 [INF] >         DirectoryExists("/Family-Files/CryptoVault")
2026-04-30 08:56:20.189 -04:00 [WRN] Reconnect needed due to disconnected control connection
2026-04-30 08:56:20.189 -04:00 [INF] Command stashed: PWD
2026-04-30 08:56:20.189 -04:00 [INF] >         Connect(True)
2026-04-30 08:56:20.190 -04:00 [WRN] Reconnect (Count: 2)
2026-04-30 08:56:20.191 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 08:56:40.387 -04:00 [INF] >         DirectoryExists("/Family-Files/CryptoVault")
2026-04-30 08:56:40.388 -04:00 [WRN] Reconnect needed due to disconnected control connection
2026-04-30 08:56:40.389 -04:00 [INF] Command stashed: PWD
2026-04-30 08:56:40.389 -04:00 [INF] >         Connect(True)
2026-04-30 08:56:40.389 -04:00 [WRN] Reconnect (Count: 3)
2026-04-30 08:56:40.390 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 08:57:00.599 -04:00 [INF] >         Dispose()
2026-04-30 08:57:00.600 -04:00 [DBG] Warning: sync dispose called for AsyncFtpClient object
2026-04-30 08:57:00.603 -04:00 [INF] >         DisposeAsync()
2026-04-30 08:57:00.603 -04:00 [DBG] Disposing(async) AsyncFtpClient
2026-04-30 08:57:00.604 -04:00 [INF] >         Disconnect()
2026-04-30 08:57:00.605 -04:00 [DBG] Connection already closed, nothing to do.
2026-04-30 08:57:00.607 -04:00 [DBG] Disposing(async) AsyncFtpClient.FtpSocketStream(control)

As mentioned, my app caught exceptions that were thrown when the code tried to use the unconnected client (maybe my code could be smarter about that). If it is helpful, I can send my app's log file that details those exceptions.

Let me know what you think.

Thanks again.

MarkBlaise avatar Apr 30 '26 15:04 MarkBlaise

CORRECTION: FluentFTP is indeed throwing exceptions - my mistake.

I started from scratch (WiFi off, reboot, etc). And it looks like the first time I try to connect, a Timeout exception is thrown. The second time gets a socket exception is thrown.

Give me a bit to sift through logs, and I'll post what I find. I just wanted to give you a heads-up about my mistake right away, to avoid sending you down the wrong rabbit hole ...

MarkBlaise avatar Apr 30 '26 15:04 MarkBlaise

OK, here is the logger file:

2026-04-30 11:40:07.016 -04:00 [INF] GetAsyncFtpClient start
2026-04-30 11:40:07.044 -04:00 [INF] GetAsyncFtpClient calling AutoConnect
2026-04-30 11:40:07.048 -04:00 [INF] >         AutoConnect()
2026-04-30 11:40:07.056 -04:00 [INF] >         AutoDetect(CloneConnection = False, FirstOnly = True, IncludeImplicit = True, AbortOnTimeout = True, RequireEncryption = False, ProtocolPriority = [Tls12])
2026-04-30 11:40:07.076 -04:00 [DBG] Auto-Detect trying encryption mode "Auto" with protocol "Tls12"
2026-04-30 11:40:07.081 -04:00 [INF] >         Connect(False)
2026-04-30 11:40:07.083 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 11:40:07.142 -04:00 [DBG] Connecting(async) AsyncFtpClient.FtpSocketStream(control) IP #1 = ***:21
2026-04-30 11:40:22.159 -04:00 [INF] >         Disconnect()
2026-04-30 11:40:22.160 -04:00 [DBG] Connection already closed, nothing to do.
2026-04-30 11:40:22.178 -04:00 [INF] >         DirectoryExists("/Family-Files/CryptoVault")
2026-04-30 11:40:22.181 -04:00 [WRN] Reconnect needed due to disconnected control connection
2026-04-30 11:40:22.181 -04:00 [INF] Command stashed: PWD
2026-04-30 11:40:22.181 -04:00 [INF] >         Connect(True)
2026-04-30 11:40:22.182 -04:00 [WRN] Reconnect (Count: 1)
2026-04-30 11:40:22.183 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 11:40:22.183 -04:00 [DBG] Connecting(async) AsyncFtpClient.FtpSocketStream(control) IP #1 = ***:21
2026-04-30 11:40:37.318 -04:00 [INF] >         DirectoryExists("/Family-Files/CryptoVault")
2026-04-30 11:40:37.319 -04:00 [WRN] Reconnect needed due to disconnected control connection
2026-04-30 11:40:37.319 -04:00 [INF] Command stashed: PWD
2026-04-30 11:40:37.319 -04:00 [INF] >         Connect(True)
2026-04-30 11:40:37.320 -04:00 [WRN] Reconnect (Count: 2)
2026-04-30 11:40:37.320 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 11:40:37.321 -04:00 [DBG] Connecting(async) AsyncFtpClient.FtpSocketStream(control) IP #1 = ***:21
2026-04-30 11:40:52.434 -04:00 [INF] >         DirectoryExists("/Family-Files/CryptoVault")
2026-04-30 11:40:52.434 -04:00 [WRN] Reconnect needed due to disconnected control connection
2026-04-30 11:40:52.435 -04:00 [INF] Command stashed: PWD
2026-04-30 11:40:52.435 -04:00 [INF] >         Connect(True)
2026-04-30 11:40:52.436 -04:00 [WRN] Reconnect (Count: 3)
2026-04-30 11:40:52.437 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 11:40:52.438 -04:00 [DBG] Connecting(async) AsyncFtpClient.FtpSocketStream(control) IP #1 = ***:21
2026-04-30 11:41:07.555 -04:00 [INF] >         Dispose()
2026-04-30 11:41:07.555 -04:00 [DBG] Warning: sync dispose called for AsyncFtpClient object
2026-04-30 11:41:07.557 -04:00 [INF] >         DisposeAsync()
2026-04-30 11:41:07.558 -04:00 [DBG] Disposing(async) AsyncFtpClient
2026-04-30 11:41:07.558 -04:00 [INF] >         Disconnect()
2026-04-30 11:41:07.559 -04:00 [DBG] Connection already closed, nothing to do.
2026-04-30 11:41:07.560 -04:00 [DBG] Disposing(async) AsyncFtpClient.FtpSocketStream(control)
2026-04-30 11:41:33.489 -04:00 [INF] GetAsyncFtpClient start
2026-04-30 11:41:33.493 -04:00 [INF] GetAsyncFtpClient calling AutoConnect
2026-04-30 11:41:33.493 -04:00 [INF] >         AutoConnect()
2026-04-30 11:41:33.494 -04:00 [INF] >         AutoDetect(CloneConnection = False, FirstOnly = True, IncludeImplicit = True, AbortOnTimeout = True, RequireEncryption = False, ProtocolPriority = [Tls12])
2026-04-30 11:41:33.495 -04:00 [DBG] Auto-Detect trying encryption mode "Auto" with protocol "Tls12"
2026-04-30 11:41:33.495 -04:00 [INF] >         Connect(False)
2026-04-30 11:41:33.495 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 11:41:53.544 -04:00 [INF] >         Disconnect()
2026-04-30 11:41:53.545 -04:00 [DBG] Connection already closed, nothing to do.
2026-04-30 11:41:53.555 -04:00 [INF] >         FileExists("/Family-Files/CryptoVault/CryptoVault-MarkBax.xml")
2026-04-30 11:41:53.558 -04:00 [INF] >         GetNameListing("/Family-Files/CryptoVault")
2026-04-30 11:41:53.559 -04:00 [WRN] Reconnect needed due to disconnected control connection
2026-04-30 11:41:53.560 -04:00 [INF] Command stashed: TYPE I
2026-04-30 11:41:53.560 -04:00 [INF] >         Connect(True)
2026-04-30 11:41:53.561 -04:00 [WRN] Reconnect (Count: 1)
2026-04-30 11:41:53.562 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 11:42:13.636 -04:00 [DBG] Connecting(async) AsyncFtpClient.FtpSocketStream(control) IP #1 = ***:21
2026-04-30 11:42:28.768 -04:00 [INF] >         FileExists("/Family-Files/CryptoVault/CryptoVault-MarkBax.xml")
2026-04-30 11:42:28.769 -04:00 [INF] >         GetNameListing("/Family-Files/CryptoVault")
2026-04-30 11:42:28.769 -04:00 [WRN] Reconnect needed due to disconnected control connection
2026-04-30 11:42:28.770 -04:00 [INF] Command stashed: TYPE I
2026-04-30 11:42:28.770 -04:00 [INF] >         Connect(True)
2026-04-30 11:42:28.771 -04:00 [WRN] Reconnect (Count: 2)
2026-04-30 11:42:28.772 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 11:42:28.773 -04:00 [DBG] Connecting(async) AsyncFtpClient.FtpSocketStream(control) IP #1 = ***:21
2026-04-30 11:42:43.889 -04:00 [INF] >         FileExists("/Family-Files/CryptoVault/CryptoVault-MarkBax.xml")
2026-04-30 11:42:43.890 -04:00 [INF] >         GetNameListing("/Family-Files/CryptoVault")
2026-04-30 11:42:43.891 -04:00 [WRN] Reconnect needed due to disconnected control connection
2026-04-30 11:42:43.891 -04:00 [INF] Command stashed: TYPE I
2026-04-30 11:42:43.891 -04:00 [INF] >         Connect(True)
2026-04-30 11:42:43.892 -04:00 [WRN] Reconnect (Count: 3)
2026-04-30 11:42:43.892 -04:00 [DBG] FluentFTP 54.1.1.0(.NET 8.0+) AsyncFtpClient
2026-04-30 11:42:43.893 -04:00 [DBG] Connecting(async) AsyncFtpClient.FtpSocketStream(control) IP #1 = ***:21
2026-04-30 11:42:59.015 -04:00 [INF] >         Dispose()
2026-04-30 11:42:59.016 -04:00 [DBG] Warning: sync dispose called for AsyncFtpClient object
2026-04-30 11:42:59.019 -04:00 [INF] >         DisposeAsync()
2026-04-30 11:42:59.020 -04:00 [DBG] Disposing(async) AsyncFtpClient
2026-04-30 11:42:59.021 -04:00 [INF] >         Disconnect()
2026-04-30 11:42:59.021 -04:00 [DBG] Connection already closed, nothing to do.
2026-04-30 11:42:59.021 -04:00 [DBG] Disposing(async) AsyncFtpClient.FtpSocketStream(control)

And here is some info from the app's exception log. You can match up the timestamps in this data with those above to get a better/more complete picture of what's going on:

***********************
30-Apr-2026 11:40:22
Error 'TimeoutException', Timed out trying to connect!
   at FluentFTP.FtpSocketStream.ConnectAsync(String host, Int32 port, FtpIpVersion ipVersions, CancellationToken token)
   at FluentFTP.AsyncFtpClient.ConnectAsync(FtpSocketStream stream, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Connect(Boolean reConnect, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Connect(CancellationToken token)
   at FluentFTP.Client.Modules.ConnectModule.AutoDetectAsync(AsyncFtpClient client, FtpAutoDetectConfig config, CancellationToken token)
   at FluentFTP.AsyncFtpClient.AutoDetect(FtpAutoDetectConfig config, CancellationToken token)
   at FluentFTP.AsyncFtpClient.AutoConnect(CancellationToken token)
   at CryptoVault.Models.Utils.GetAsyncFtpClient(String host, CancellationToken token, NetworkCredential creds) in E:\Projects\Maui\CryptoTest\CryptoVaultAndroidApp\Models\Utilities.cs:line 2260

***********************
30-Apr-2026 11:40:37
Error 'TimeoutException', Timed out trying to connect!
   at FluentFTP.FtpSocketStream.ConnectAsync(String host, Int32 port, FtpIpVersion ipVersions, CancellationToken token)
   at FluentFTP.AsyncFtpClient.ConnectAsync(FtpSocketStream stream, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Connect(Boolean reConnect, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, Int32 linesExpected, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, CancellationToken token)
   at FluentFTP.AsyncFtpClient.ReadCurrentWorkingDirectory(CancellationToken token)
   at FluentFTP.AsyncFtpClient.GetWorkingDirectory(CancellationToken token)
   at FluentFTP.AsyncFtpClient.DirectoryExists(String path, CancellationToken token)
   at CryptoVault.Models.Utils.CloudFolderExistsFtpAsync(String dirSpec, Int32 retries, NetworkCredential creds) in E:\Projects\Maui\CryptoTest\CryptoVaultAndroidApp\Models\Utilities.cs:line 1067

***********************
30-Apr-2026 11:40:52
Error 'TimeoutException', Timed out trying to connect!
   at FluentFTP.FtpSocketStream.ConnectAsync(String host, Int32 port, FtpIpVersion ipVersions, CancellationToken token)
   at FluentFTP.AsyncFtpClient.ConnectAsync(FtpSocketStream stream, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Connect(Boolean reConnect, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, Int32 linesExpected, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, CancellationToken token)
   at FluentFTP.AsyncFtpClient.ReadCurrentWorkingDirectory(CancellationToken token)
   at FluentFTP.AsyncFtpClient.GetWorkingDirectory(CancellationToken token)
   at FluentFTP.AsyncFtpClient.DirectoryExists(String path, CancellationToken token)
   at CryptoVault.Models.Utils.CloudFolderExistsFtpAsync(String dirSpec, Int32 retries, NetworkCredential creds) in E:\Projects\Maui\CryptoTest\CryptoVaultAndroidApp\Models\Utilities.cs:line 1067

***********************
30-Apr-2026 11:41:07
Error 'TimeoutException', Timed out trying to connect!
   at FluentFTP.FtpSocketStream.ConnectAsync(String host, Int32 port, FtpIpVersion ipVersions, CancellationToken token)
   at FluentFTP.AsyncFtpClient.ConnectAsync(FtpSocketStream stream, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Connect(Boolean reConnect, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, Int32 linesExpected, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, CancellationToken token)
   at FluentFTP.AsyncFtpClient.ReadCurrentWorkingDirectory(CancellationToken token)
   at FluentFTP.AsyncFtpClient.GetWorkingDirectory(CancellationToken token)
   at FluentFTP.AsyncFtpClient.DirectoryExists(String path, CancellationToken token)
   at CryptoVault.Models.Utils.CloudFolderExistsFtpAsync(String dirSpec, Int32 retries, NetworkCredential creds) in E:\Projects\Maui\CryptoTest\CryptoVaultAndroidApp\Models\Utilities.cs:line 1067

***********************
30-Apr-2026 11:41:53
Error 'SocketException', hostname nor servname provided, or not known
   at System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses, AddressFamily addressFamily, Nullable`1 activityOrDefault)
   at System.Net.Dns.GetHostAddressesCore(String hostName, AddressFamily addressFamily, Nullable`1 activityOrDefault)
   at System.Net.Dns.<>c.<GetHostEntryOrAddressesCoreAsync>b__33_0(Object s, NameResolutionActivity activity)
   at System.Net.Dns.<>c__DisplayClass39_0`1[[System.Net.IPAddress[], System.Net.Primitives, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].<RunAsync>b__0(Task <p0>, Object <p1>)
   at System.Threading.Tasks.ContinuationResultTaskFromTask`1[[System.Net.IPAddress[], System.Net.Primitives, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__292_0(Object obj)
   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.GetCachedHostAddressesAsync(String host, CancellationToken token)
   at FluentFTP.FtpSocketStream.ConnectAsync(String host, Int32 port, FtpIpVersion ipVersions, CancellationToken token)
   at FluentFTP.AsyncFtpClient.ConnectAsync(FtpSocketStream stream, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Connect(Boolean reConnect, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Connect(CancellationToken token)
   at FluentFTP.Client.Modules.ConnectModule.AutoDetectAsync(AsyncFtpClient client, FtpAutoDetectConfig config, CancellationToken token)
   at FluentFTP.AsyncFtpClient.AutoDetect(FtpAutoDetectConfig config, CancellationToken token)
   at FluentFTP.AsyncFtpClient.AutoConnect(CancellationToken token)
   at CryptoVault.Models.Utils.GetAsyncFtpClient(String host, CancellationToken token, NetworkCredential creds) in E:\Projects\Maui\CryptoTest\CryptoVaultAndroidApp\Models\Utilities.cs:line 2260

***********************
30-Apr-2026 11:42:28
Error 'TimeoutException', Timed out trying to connect!
   at FluentFTP.FtpSocketStream.ConnectAsync(String host, Int32 port, FtpIpVersion ipVersions, CancellationToken token)
   at FluentFTP.AsyncFtpClient.ConnectAsync(FtpSocketStream stream, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Connect(Boolean reConnect, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, Int32 linesExpected, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, CancellationToken token)
   at FluentFTP.AsyncFtpClient.SetDataTypeNoLockAsync(FtpDataType type, CancellationToken token)
   at FluentFTP.AsyncFtpClient.GetNameListing(String path, CancellationToken token)
   at FluentFTP.AsyncFtpClient.FileExists(String path, CancellationToken token)
   at CryptoVault.Models.Utils.CloudFileExistsFtpAsync(String fileSpec, Int32 retries) in E:\Projects\Maui\CryptoTest\CryptoVaultAndroidApp\Models\Utilities.cs:line 1140

***********************
30-Apr-2026 11:42:43
Error 'TimeoutException', Timed out trying to connect!
   at FluentFTP.FtpSocketStream.ConnectAsync(String host, Int32 port, FtpIpVersion ipVersions, CancellationToken token)
   at FluentFTP.AsyncFtpClient.ConnectAsync(FtpSocketStream stream, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Connect(Boolean reConnect, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, Int32 linesExpected, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, CancellationToken token)
   at FluentFTP.AsyncFtpClient.SetDataTypeNoLockAsync(FtpDataType type, CancellationToken token)
   at FluentFTP.AsyncFtpClient.GetNameListing(String path, CancellationToken token)
   at FluentFTP.AsyncFtpClient.FileExists(String path, CancellationToken token)
   at CryptoVault.Models.Utils.CloudFileExistsFtpAsync(String fileSpec, Int32 retries) in E:\Projects\Maui\CryptoTest\CryptoVaultAndroidApp\Models\Utilities.cs:line 1140

***********************
30-Apr-2026 11:42:58
Error 'TimeoutException', Timed out trying to connect!
   at FluentFTP.FtpSocketStream.ConnectAsync(String host, Int32 port, FtpIpVersion ipVersions, CancellationToken token)
   at FluentFTP.AsyncFtpClient.ConnectAsync(FtpSocketStream stream, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Connect(Boolean reConnect, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, Int32 linesExpected, CancellationToken token)
   at FluentFTP.AsyncFtpClient.Execute(String command, CancellationToken token)
   at FluentFTP.AsyncFtpClient.SetDataTypeNoLockAsync(FtpDataType type, CancellationToken token)
   at FluentFTP.AsyncFtpClient.GetNameListing(String path, CancellationToken token)
   at FluentFTP.AsyncFtpClient.FileExists(String path, CancellationToken token)
   at CryptoVault.Models.Utils.CloudFileExistsFtpAsync(String fileSpec, Int32 retries) in E:\Projects\Maui\CryptoTest\CryptoVaultAndroidApp\Models\Utilities.cs:line 1140

So it seems that without a network:

  • without cached dns data, FluentFTP behaves as designed
  • with cached dns, something else is going on.

If you want to provide me with a build that generates more logging, I'd be happy to run that for you.

Let me know what you want to do.

Thanks again!

MarkBlaise avatar Apr 30 '26 16:04 MarkBlaise

As mentioned, my app caught exceptions that were thrown...

Yes, you should react to those exceptions instead of blithely continuing - but maybe it is autoconnect that is continuing, not you. Autoconnect could be buggy when the individual connect attempts fail? Worth investigating, I suppose.

with cached dns, something else is going on.

So, that confirms what I thought.

without cached dns data, FluentFTP behaves as designed

Not totally, there was one exception in there that was not timeout. I wonder how that came to be.


There is a possible workaround in that you might test network availability before accessing a FluentFTP client?


Now, I would prefer if for the following tests you could recode your app to only use one server that you know well and to use connect instead of autoconnect. This aims to simplify the process. Just do a connect followed by a disconnect. And then use a special fork/branch to diagnose this. I'll try to whip something up by monday.

FanDjango avatar Apr 30 '26 18:04 FanDjango

Not totally, there was one exception in there that was not timeout.

Are you talking about the "SocketException"? Yes, what I noticed was that the first time I try to make a connection it is done via AutoConnect, and the timeout exception is thrown. The second time AutoConnect is called the socket exception is thrown.

Note that the other timeout exceptions are thrown when my code tries to use the unconnected ftp client. In the stack traces from my exception log, the last line shows the caller from my code - GetAsyncFtpClient (where I connect) or CloudFileExistsFtpAsync (where the connection is used).

There is a possible workaround in that you might test network availability before accessing a FluentFTP client?

Yes, I can try that. To your credit, FluentFTP has worked well enough that nothing like that has been necessary ... until now ;-)

Now, I would prefer if for the following tests you could recode your app to only use one server that you know well and to use connect instead of autoconnect.

Yes, I can do that too. I guess can use the connection profile generated by a successful autoconnect call, right?

It also occurs to me that I could probably create a simple VS 2022 Maui project that uses Fluent to repro the issue, and you could test with that. Let me know if that sounds like a good approach to you.

Thank you for your help.

MarkBlaise avatar Apr 30 '26 23:04 MarkBlaise

It also occurs to me that I could probably create a simple VS 2022 Maui project that uses Fluent to repro the issue, and you could test with that. Let me know if that sounds like a good approach to you.

This is what I was suggesting. For the testing only.


The fork/branch you should test with is ready. You can find it under https://github.com/FanDjango/FluentFTP/tree/connecthang

It encapsulates the steps to connect with try-catch and log messages - these will tell us more about what is going on, I hope.

So please try your dastardly deeds, let's see how those changes work - and we should know more about exactly which internal function "hangs".

Mind you, when experimenting with android and MAUI, VS 2026 and in debug mode, I have experienced hangs quite often, and needed to restart my app, lo and behold: no hang.

You wrote (further up):

but emulators can sometimes be a bit flaky

That's my observation also.

FanDjango avatar May 01 '26 09:05 FanDjango

This is what I was suggesting.

Yeah, I realize that now. I'm a bit neurodivergent, so I missed the suggestion in your earlier comment about limited experience with Maui. Sorry about that.

FWIW, I have not yet installed VS 2026, so the project will be from VS 2022. That probably won't matter, but one never knows when you get thick into the weeds. I'll let you know when the project is ready for you.

To be sure we're on the same page, when testing calls to Connect, I can use a connection profile generated by a successful AutoConnect call, yes?

I probably won't get to this today - Fridays tend to be pretty hectic around here. But I should be able to work on this over the weekend. My experience with github is very limited. At the link you provided, there are a number of links that appear to lead to code. Which of these did you intend me to download? I would guess that it's the one named "FluentFTP", with a commit message of "formatting" and a commit date of "3 hours ago", but I'd like to confirm that assumption.

Have a good weekend, and thanks again for your help!

MarkBlaise avatar May 01 '26 12:05 MarkBlaise

Image Image


Essentially, instead of getting it from Nuget, you create your own solution, which contains a FluentFTP project.

Build it.

Then instead of referencing NuGet, reference the correct bin folder and FluentFTP dll of your own build. VS 2022 should be perfectly ok.

If you have problems, ask me.

Most of these changes are so useful that I think they will make it into the "official" master and NuGet, but it will take a while for the next release to take place, so this method is the way to go.

FanDjango avatar May 01 '26 13:05 FanDjango

OK, I was able to have a look. Using the build you provided, the problem does not occur! Without WiFi, I am now getting the timeout exception, as one would ordinarily expect.

I am attaching 4 log files:

  • FtpLog-Connect-OK.txt: calls Connect with WiFi turned on
  • FtpLog-Connect-NG.txt: calls Connect with WiFi turned off
  • FtpLog-AutoConnect-OK.txt: calls Connect with WiFi turned on
  • FtpLog-AutoConnect-NG.txt: calls Connect with WiFi turned off

FtpLog-Connect-OK.txt

FtpLog-Connect-NG.txt

FtpLog-AutoConnect-OK.txt

FtpLog-AutoConnect-NG.txt

This is all with AsyncFtpClient. In each of these files, I appended the relevant entries from my app log file. I don't know what is different, but the behavior has changed.

Let me know what you think. I have made a number of changes to my code to accommodate testing, but nothing that I think would be responsible for the behavior change. FWIW, it's not just the emulator. I was getting the hang on a Galaxy S25 phone too

Minor point, the code emitted by profile.ToCode() has a minor error, VS does not like that last line about encoding: Encoding = System.Text.UTF8Encoding

Image

VS is happier with that last line like so: Encoding = System.Text.UTF8Encoding.UTF8

Thanks again for your help.

MarkBlaise avatar May 01 '26 21:05 MarkBlaise

I'll investigate this a bit further and then merge the changes into the current master upstream.

I will keep you posted here - and also when it finally gets merged into the next NuGet release.

Thanks for your help/input,

FanDjango avatar May 01 '26 22:05 FanDjango

VS is happier with that last line like so: Encoding = System.Text.UTF8Encoding.UTF8

Could you please open this a separate issue - as at the moment my queue is so full it might get lost

FanDjango avatar May 01 '26 22:05 FanDjango

It's merged into master, wait for NuGet release. Any further problems -> new Issue please.

FanDjango avatar May 01 '26 22:05 FanDjango

Could you please open this a separate issue

Of course, no problem.

Thank you for your time and effort, I sincerely appreciate it.

Have a great weekend!

MarkBlaise avatar May 01 '26 22:05 MarkBlaise

Let me add one comment:

What has changed?

Well, before, no failure was duly noted and reacted to - there was a certain non-chalance and the expectation that the final connect attempt would "catch" all the previous failures to prepare things correctly for the connect.

The new code tries to fail a few things in advance.

The original intent on my part was to identify the point of failure/hang. But in the end, the changes were more on the idea of catching failures and throwing, instead of just "blithely" going on.

FanDjango avatar May 01 '26 22:05 FanDjango