phpseclib always gives login failed with no log

﹥>﹥吖頭↗ 提交于 2019-12-11 07:18:08

问题


I am using phpseclib. I copied all the files into a folder on my www directory.

First i do

$sftp = new Net_SFTP($this->host,$this->port)

which works fine

and then i do

if(!$sftp->login($this->user,$this->pass)) {
                print_r($sftp->getErrors());
                echo $sftp->getLog();
                exit('Login Failed');
            }

It always gives me invalid username and passoword.

I have also done define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);

but when i do getLog or getErrors i dont get any errors or logs at all.

When i use filezilla using SFTP mode it logins just fine so that means the username and password are correct.

Can someone please advise.

Thanks,

<?php
error_reporting(E_ALL);
require_once('../includes/3rdparty/phpseclib1.0.9/Net/SFTP.php');
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
////////////////////////////////////////////////////
//
// Class for dealing with FTP
//
////////////////////////////////////////////////////

class FTPfile
{
    protected $host         = "localhost";
    protected $port         = "4222";
    protected $user         = "Anonymous";
    protected $pass         = "Email";
    protected $link_id      = "";
    protected $is_login     = "";
    protected $debug        = 1;
    protected $local_dir    = "";
    protected $rootdir      = "";
    protected $dir          = "/";

    /**
    * constructor.
    * @return void
    */
    public function __construct($user = "Anonymous", $pass = "Email", $host = "localhost", $port = "21")
    {
        if($host) $this->host = $host;
        if($port) $this->port = $port;
        if($user) $this->user = $user;
        if($pass) $this->pass = $pass;
        $this->login();
    $this->dir = $this->rootdir;
    }

    /**
    * halt.
    * @return void
    */
    public function halt($msg, $line = __LINE__)
    {
        echo "FTP Error in line: $line<br/>\n";
        echo "FTP Error message: $msg<br/>\n";
        exit();
    }

    /**
    * login.
    * @return void
    */
    public function login()
    {
        if(!$this->link_id)
        {
            $sftp = new Net_SFTP($this->host,$this->port) or $this->halt("can not connect to host:$this->host:$this->port", __LINE__);
        }
        if(!$this->is_login)
        {

            if(!$sftp->login($this->user,$this->pass)) {
                print_r($sftp->getErrors());
                echo $sftp->getLog();
                exit('Login Failed');
            }


        }
    }
}

?>

回答1:


My guess: the socket connection isn't able to be opened. To confirm, open up SSH2.php and find all instances of @fsockopen and @stream_select and replace them with fsockopen and stream_select (ie. remove the error suppression operator). My guess is that you'll see an error message from either of those functions once you do that.




回答2:


Instead of using 'NET_SSH2_LOG_COMPLEX' i used '2' and all of a sudden all the problems disappeared. No problem logging in and also logs were generated.



来源:https://stackoverflow.com/questions/48319896/phpseclib-always-gives-login-failed-with-no-log

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!