Misafir; sen atmıştında ssh2 kısmı çalıştı ama sftp çalışmadı
hata bu
[11-Feb-2025 05:18:28 Europe/Istanbul] PHP Fatal error: Uncaught Error: Call to undefined method phpseclib3NetSSH2::getServerHost() in /home/oyuncul2/public_html/sistem/ogcp_ssh2.php:48 Stack trace: #0 /home/oyuncul2/public_html/page_func/Eklenti_Kontrol.php(22): ogcp_ssh2->SFTP_DownloadFile('/root/cs1/cstri...', 'tmp/tmp_195.93....') #1 /home/oyuncul2/public_html/index.php(119): require_once('/home/oyuncul2/...') #2 {main} thrown in /home/oyuncul2/public_html/sistem/ogcp_ssh2.php on line 48
<?php
use phpseclib3\Net\SSH2;
use phpseclib3\Net\SFTP;
require __DIR__ . '/vendor/autoload.php';
class ogcp_ssh2 {
private $ssh;
private $sftp;
private $error;
private $host;
private $port;
private $username;
private $password;
public function __construct() {
$this->ssh = null;
$this->sftp = null;
$this->error = "";
$this->host = '';
$this->port = 22;
$this->username = '';
$this->password = '';
}
public function Connect($host, $port = 22) {
if ($host == "") return false;
$this->host = $host;
$this->port = $port;
$this->ssh = new SSH2($host, $port);
if ($this->ssh) {
return true;
} else {
$this->error = 'Error #01: Server not found!';
return false;
}
}
public function ConnectwAuth($host, $port = 22, $user, $pass) {
if ($host == "" || $user == "" || $pass == "") return false;
if ($this->Connect($host, $port)) {
$this->username = $user;
$this->password = $pass;
if ($this->ssh->login($user, $pass)) {
return true;
} else {
$this->error = 'Error #02: Authentication rejected by server!';
return false;
}
}
$this->error = 'Error #01: Server not found!';
return false;
}
public function SFTP_DownloadFile($remote, $local) {
if (!$this->sftp) {
// Burada host ve port bilgilerini doğrudan kullanıyoruz
$this->sftp = new SFTP($this->host, $this->port);
$this->sftp->login($this->username, $this->password);
}
return $this->sftp->get($remote, $local);
}
public function SFTP_UploadFile($local, $remote) {
if (!$this->sftp) {
// Burada host ve port bilgilerini doğrudan kullanıyoruz
$this->sftp = new SFTP($this->host, $this->port);
$this->sftp->login($this->username, $this->password);
}
return $this->sftp->put($remote, $local, SFTP::SOURCE_LOCAL_FILE);
}
public function OpenSFTP() {
// Burada host ve port bilgilerini doğrudan kullanıyoruz
$this->sftp = new SFTP($this->host, $this->port);
if ($this->sftp->login($this->username, $this->password)) {
return true;
} else {
$this->error = 'Error #03: SFTP Connection rejected!';
return false;
}
}
public function SFTP_ReadFile($filepath) {
if ($filepath == "") return false;
if (!$this->sftp) {
$this->OpenSFTP();
}
return $this->sftp->get($filepath);
}
public function SFTP_FileLink($filepath) {
return $filepath;
}
public function Disconnect() {
$this->ssh->disconnect();
$this->sftp = null;
$this->ssh = null;
return null;
}
public function Exec($cmd) {
return $this->ssh->exec($cmd);
}
}
?>