-2

i was testing my code only in my controler and it worked, when i went to put all in the model and call the functions in the controller it wont connect to the sftp server.

    require "vendor/autoload.php";
    use phpseclib\Net\SFTP;

class sftpInno extends SFTP{

        private $Host;
        private $Port;
        private $Username;
        private $Password;


    public function __construct()
    {

        $this->Host = '192.168.61.192';
        $this->Port = '99';
        $this->Username = 'tester';
        $this->Password = 'password';

    }

    public function SFTPLogin()
    {
        $return = true;

        if (!$this->login($this->Username, $this->Password)) {
            $return = false;
        }

        return $return;
    }

Controller

    $InnoSFT = new sftpInno();

$return = $InnoSFT->SFTPLogin();

Any toughts? Thanks

Alexis Garcia
  • 452
  • 3
  • 15

1 Answers1

2

You should do parent::__construct($this->Host, $this->Port) in your constructor. The constructor for phpsecib's SFTP class (and SSH2 class) do do stuff after all:

https://github.com/phpseclib/phpseclib/blob/2.0.21/phpseclib/Net/SFTP.php#L273 https://github.com/phpseclib/phpseclib/blob/2.0.21/phpseclib/Net/SSH2.php#L953

If you have further issues then update your post to include the SSH logs. You can get them by doing define('NET_SSH2_LOGGING', 2); at the top and then echo $this->getLog(); after the login attempt.

neubert
  • 15,947
  • 24
  • 120
  • 212