[英]phpseclib always gives login failed with no log
我正在使用phpseclib。 我將所有文件復制到www目錄下的文件夾中。
我先做
$ sftp =新的Net_SFTP($ this-> host,$ this-> port)
哪個工作正常
然后我做
if(!$sftp->login($this->user,$this->pass)) {
print_r($sftp->getErrors());
echo $sftp->getLog();
exit('Login Failed');
}
它總是給我無效的用戶名和密碼。
我也做過define('NET_SSH2_LOGGING',NET_SSH2_LOG_COMPLEX);
但是當我做getLog或getErrors時,我根本不會得到任何錯誤或日志。
當我使用SFTP模式使用filezilla時,它會很好地登錄,這意味着用戶名和密碼是正確的。
有人可以建議。
謝謝,
<?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');
}
}
}
}
?>
我猜:套接字連接無法打開。 要確認,打開SSH2.php並找到@fsockopen
和@stream_select
所有實例,並用fsockopen
和stream_select
替換它們(即刪除錯誤抑制操作符)。 我的猜測是,一旦你這樣做,你會看到來自這兩個函數的錯誤信息。
我沒有使用'NET_SSH2_LOG_COMPLEX',而是使用'2'而突然間所有問題都消失了。 登錄沒問題,也生成了日志。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.