FluentFTP: auto-reconnect not connecting when it is needed for capabilites access

FTP Server OS: Any

FTP Server Type: Any

Client Computer OS: Any

FluentFTP Version: 52.0.0

Framework: .NET 8

This is not really an error with FluentFTP, but more a confusing auto-feature, that was hard to isolate because it “mostly works”. Only in some cases where a retry (outside of FluentFTP) is attempted, this would get triggered. This got mixed up in #1690 because that is one way to trigger it.

I distilled it down to the following code that works:

var client = new AsyncFtpClient() { ... };
var dir = await client.GetWorkingDirectory();
await client.UploadStream(...);

But if you do not read the working directory, you get an exception with the message “Please call Connect() before trying to read the Capabilities!”:

var client = new AsyncFtpClient() { ... };
await client.UploadStream(...);

It is of course an error not to call await client.Connect(), so one could argue that this is as intended. But the fact that some methods will automatically (re-)connect and others not makes it confusing. In my case it was hard to pin down, because the List method appears to connect automatically.

I would suggest either making all methods auto-connect or all methods not auto connecting. Alternatively, you could consider checking the state of the client on the various calls to give an earlier exception/stack-trace that makes it clear it is the caller making the mistake, and not an internal check that fails.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17

Commits related to this issue

Most upvoted comments

Any way you could use it prior to it being released?

Not really unfortunately. I am not the end-user myself, so I do not have the issue directly. I can test the update, but after I added the Connect() call, I have not had any issues. I reverted my change to avoid calling Connect() to provide the extra data listed here.

Yes, we have some legacy surrounding Dispose() so all disposing is done synchronously.

Ok, fine with that.

Yes, and because I did not call Connect() I think it is treated as **re-**connect, but there was never a connect, so the capabilities are not known.

Good, so that explains it well.

This is the full log, everything that was printed was exactly that. From what I see, it never connects to the server. If there is a “extra verbose log” flag that I can add, I can try that.

Ok, so the entire sequence starts with UploadStream. That was for me hard to believe so I assumed there was stuff prior to that missing.

Well, with the new PR, when it is finally put in production - you can perhaps choose to specifiy client.Config.SelfConnectMode = FtpSelfConnectMode.OnConnectionLost.

Which brings us back to the original discussion

I would suggest either making all methods auto-connect or all methods not auto connecting.

which the new PR then cleanly adresses.

I am still putting some finishing touches to it but it’s nearly there…