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
- Merge pull request #1702 from FanDjango/master Reconcile #683 and #1698, step 1 — committed to robinrodricks/FluentFTP by FanDjango 2 years ago
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 callingConnect()to provide the extra data listed here.Ok, fine with that.
Good, so that explains it well.
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
which the new PR then cleanly adresses.
I am still putting some finishing touches to it but it’s nearly there…