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
SFTP: Connection closed by server (TurboFTP) but works fine with WinSCP + Login PUTTY ok #1957
Comments
Looks like it's happening here: $packet = Strings::packSSH2('Cs', NET_SSH2_MSG_SERVICE_REQUEST, 'ssh-userauth');
$this->send_binary_packet($packet);
try {
$response = $this->get_binary_packet();
} catch (\Exception $e) {
if ($this->retry_connect) {
$this->retry_connect = false;
$this->connect();
return $this->login_helper($username, $password);
}
$this->disconnect_helper(NET_SSH2_DISCONNECT_CONNECTION_LOST);
throw new ConnectionClosedException('Connection closed by server');
} It'd be cool if you could post the exact exception that you're getting, complete with line numbers, so that I can be sure but in lieu of that I guess that we can just assume that it is. So in lieu of that I think that what'd be helpful is if you can modify that line of code to replace Also, if you could enable logging in WinSCP as described at https://winscp.net/eng/docs/logging and set the Logging level to Debug 2 that'd be helpful. What I'm interested in seeing is the cipher suite that WinSCP is using. My guess is that WinSCP is using a different cipher suite than phpseclib and that the server just has buggy implementations of one algorithm or another. |
Like in my WinSCP instance it's prioritizing aes256-ctr over aes256-gcm@openssh.com (which is what phpseclib preferentially uses). So based on that I wonder if this might work: $ssh->setPreferredAlgorithms(['client_to_server' => ['crypt' => ['aes256-ctr']], 'server_to_client' => ['crypt' => ['aes256-ctr']]]); You'd want to do that right after the constructor before you actually try to login. Is https://turboftp.com/ftp-sftp-server-faq what you're connecting to? |
@terrafrost I'm not sure how I was able to get it from "connection closed by server" to "invalid size" (actually catching the exception?) Your suggestion works, maybe there should be a fallback if something like this happens? I believe it is Turbo FTP as that's what it says in the logs, It's not my server.
|
What I'll prob do is look at the server identitier and if it's TurboFTP it
just won't try aes gcm.
I'm not gonna have phpseclib brute force algorithm combinations until it
finds one that works cause it's possible no combo will work and that the
problem lies elsewhere. Like taking 30s to fail vs 1s is kinda distasteful.
The server identifier special handling is a pretty standard way of dealing
with these kinds of issues. See, for example,
https://the.earth.li/~sgtatham/putty/0.79/htmldoc/Chapter4.html#config-ssh-bugs
I'll work on this in a few days. I'm at https://www.longhornphp.com/ today!
Glad to hear the work around worked!
…On Sat, Nov 4, 2023, 8:26 AM Wesley ***@***.***> wrote:
@terrafrost <https://github.com/terrafrost> I'm not sure how I was able
to get it from "connection closed by server" to "invalid size" (actually
catching the exception?)
Stack below.
Your suggestion works, maybe there should be a fallback if something like
this happens?
Or is this already possible?
I believe it is Turbo FTP as that's what it says in the logs, It's not my
server.
RuntimeException: Invalid size in /home/wehaadmi/public_html/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:3713
Stack trace:
#0 /home/wehaadmi/public_html/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php(3514): phpseclib3\Net\SSH2->read_remaining_bytes(1996473778)
#1 /home/wehaadmi/public_html/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php(2319): phpseclib3\Net\SSH2->get_binary_packet()
#2 /home/wehaadmi/public_html/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php(2212): phpseclib3\Net\SSH2->login_helper('user')
#3 /home/wehaadmi/public_html/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php(2185): phpseclib3\Net\SSH2->sublogin('user')
#4 /home/wehaadmi/public_html/includes/functions_global.php(2378): phpseclib3\Net\SSH2->login('user', 'password')
—
Reply to this email directly, view it on GitHub
<#1957 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABULSRJDF7RM7WWLR3FOQLYCY66VAVCNFSM6AAAAAA64SGEPWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJTGQ2DGMBVGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
3ecde6b should fix this. Thanks! |
@terrafrost that works!, thanks! |
I'm trying to connect to an SFTP server but it says "connection closed by server"
When I go deeper in the code it fails at "Invalid size" in SSH2.php
I can connect just fine with WinSCP and browser / download files.
When I try to connect with putty it gives me a succesful login but of course no SSH TTY possible
Phpseclib seems to stop at the user entry or just before password entry.
phpseclib log:
The text was updated successfully, but these errors were encountered: