Skip to content
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

How to handle this error? #1938

Open
mikmikmik opened this issue Sep 13, 2023 · 3 comments
Open

How to handle this error? #1938

mikmikmik opened this issue Sep 13, 2023 · 3 comments
Labels

Comments

@mikmikmik
Copy link

mikmikmik commented Sep 13, 2023

I had this error happening once:

PHP Fatal error:  Uncaught RuntimeException: Error reading from socket in /home/.../vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:1382
Stack trace:
#0 /home/.../vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php(2205): phpseclib3\Net\SSH2->connect()
#1 /home/.../vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php(2184): phpseclib3\Net\SSH2->sublogin('login')
#2 /home/.../someplugin.php(423): phpseclib3\Net\SSH2->login('login', 'pass')
#3 /home/.../class-api.php(161): MyClass->send_file_to_ftp('filename', '<?xml version="...')

Here's the function:

            private function send_file_to_ftp($filename, $xml):bool
            {

                $sftp = new \phpseclib3\Net\SFTP($this->sftp_url, 22);
                if (!$sftp->login($this->sftp_user, $this->sftp_pass)) {
                    exit('Login Failed');
                }
                $sftp->chdir('FOLDER');
                $status = $sftp->put($filename, $xml);
                return $status;

            }
@mikmikmik mikmikmik changed the title How to handle this error to log it in php? How to handle this error? Sep 13, 2023
@mikmikmik
Copy link
Author

mikmikmik commented Sep 13, 2023

Will the following work to have some log in my admin?

$login = $sftp->login($this->sftp_user, $this->sftp_pass);
if (!$login) {
    return false;
}

@mikmikmik
Copy link
Author

mikmikmik commented Sep 13, 2023

I actually had the answer in the Error, it's an Uncaught RuntimeException so I should use a try catch...
It's referenced in the docs

@terrafrost
Copy link
Member

Yah - as it's throwing an exception you'd need to catch it.

That said, if you want to understand why it's not connecting, enabling logging by doing define('NET_SSH2_LOGGING', 2); at the top and echo $ssh->getLog(); after the error would be helpful. Then post the output here and I can take a look.

@bantu bantu added the support label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants