-
-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
auto-reconnect not connecting when it is needed for capabilites access #1698
Comments
I agree.
I have spent very many hours myself tracking down the sort of problems you mention. not auto connecting would be my choice. The only kind of "hidden" or "secret" re-connect then left over, would be the one that happens in the case of stale data being left over on the socket prior to the next command that needs to be sent to the server, although even that reconnect is a sort of kludge to clear up strange connection states. Getting that to work was up to now quite difficult, think about re-creating the state of the control session, the current directory, the current transfer type (binary/ascii) etc. Any custom servers (like z/OS, for example) might introduce more things that would need to be restored. It was not my decision to do these things, auto-connect, auto-re-connect. They have a number of advantages, but meh. The intention was to make things easier for the user, so he does not need to do the kind of checking he isn't really familiar with, FTP being such a strange protocol which is also not implemented consistently across all servers regarding the RFCs. But the implementation is not totally clean, and thus you have admirably described the current state of affairs. Thanks for that. The real question is: What to do? I know of users who code their download by creating the client, calling the download API and that's that. They don't even know anything about "Connecting" and much less about a possible need to "Disconnect". That was really a good thing: Isolating the user from even knowing there is a protocol. |
As per this, I have yet to actually get enough information to actually understand what caused that problem in your case. Some source code, a detailed FluentFTP log and a good pair of eyes, and lo and behold, one arrives at an explanation. But I feel like I am being fed little problem tidbits taste by taste and my crystal ball is very cloudy. I don't understand the connection of this issue to #1960. |
I see your point, most people do not understand FTP and the logic is also not really easy to understand if you are used to stateless requests (like HTTP). If you view it this way, I would argue that the If you view it as an FTP library (giving abstract access to an FTP server), I would argue that the auto-connect feature should be removed, and the caller is responsible for state management. A solution could be to support both, by having a
What happened here was that the underlying socket would time out, closing the connection. Because the You do not need to understand the connection, I was just trying to clear up why the other issue got so messy. |
Ok, I see.
I am thinking about that possibility too. Your two alternative szenarios, that you described, are an exact description of the real word - we have both kinds of users. Although I do not see what type are in the majority. So: We could create one or two flags, defaulting to the "easy" mode, which steer the behaviour. AutoConnect.Never Never autoconnect nor autoreconnect
AutoConnect.OnlyReconnect Only autoconnect when connection drops
AutoConnect.Always Autoconnect whenever needed <----DEFAULT Should put this on the TODO list. |
Once again quick solutions may be suspect, after some looking at the code, I disagree with the analysis above. Fact is: All calls to the API that end in a call to Execute(...) (attempts to send a command on the control connection) will enact a (re-)connect if no connection exists.. ALL OF THEM (unless there is a bug in that logic, even there). So if you create a client, it is not connected at first. Call an API and you will be connected. Unless there is a bug somewhere, and actually, there is. Any API that checks the servers capabilites before you are connected will get this error. Some other APIs might exhibit other errors, this needs to be checked, perhaps. Because those capabilities are only set when a connect takes place. That is the actual error which also is a fixable error. The workaround of course, is to connect after creating a client, as you said. My fix, some time in the future, will be to connect if someone calls an API that needs to query capabilites before beginning its work, the actual bug. |
Oh, but I still believe this here is a good idea and needs doing: AutoConnect.Never Never autoconnect nor autoreconnect
AutoConnect.OnlyReconnect Only autoconnect when connection drops
AutoConnect.Always Autoconnect whenever needed <----DEFAULT |
Using your code (well, using UploadFile instead of UploadStream) without doing a connect: await using var client = new AsyncFtpClient("bla", "bla", "bla");
await client.UploadFile(@"D:\testdir\gentoo_root.img", @"/home/bla/test/gentoo_root.img", FtpRemoteExists.Overwrite, false, FtpVerify.None);
} I do not get the error message you stated (in this issue and in others).
So, you can see that your error message must be issued in some other context. Without some detailed information there is hardly any way to clear up these mixed up issues. And we are forever going off on some tangent or wild goose chase using the snippets of information and wild guesses. You've even got me doing it too... Of course, the question remains open: Exactly what sequence of events led to the error message "Please call connect() etc. etv." being issued"? So IMHO we should focus on that as a first priority, before we talk about what to do with AutoConnect yes/no. I feel that we don't have the total picture yet. Notice that there is a lot of PWD / CWD activity in my log. That's because the client.Config.Autonavigate setting is in effect. That causes the first command to be PWD, which then causes the (automatic) Connect. If I had a log from you, and/or detailed config information, I might be able to see that something else or some other sequence is happening, where the capabilities are queried before any connect takes places. This way, I am spending hours with conjecture and trying to recreate theoretical scenarios to no avail. |
Because this continues to worry me, I tried to follow your example code more exactly. Looks like I found the actual reason for the "Please call connect() etc. etv." being issued"? message. It seems you are probably using In this mode, the problem you described becomes apparent. I am wondering what other possible way one could provoke this, but none come to mind right away. I'll try to fix that in a good way but it won't be easy.
|
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:
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!":
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.
The text was updated successfully, but these errors were encountered: