şunu dener misiniz
<?php
use phpseclib3\Net\SSH2;
use phpseclib3\Net\SFTP;
require '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 = "";
}
public function Connect($host, $port = 22) {
if ($host == "") return false;
$this->host = gethostbyname($host);
$this->port = $port;
$this->ssh = new SSH2($this->host, $this->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;
$this->username = $user;
$this->password = $pass;
if ($this->Connect($host, $port)) {
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) {
$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) {
$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() {
$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);
}
}
?>
hiç bir error log yazmıyor ama biraz oldu gibi sadece sftp işlemleri yapmıyor oda zannediyorsam bu classda sftp:// olmadığı için orjinali buydu
<?php
class ogcp_ssh2 {
private $socket;
private $sftp;
private $error;
##### Constructor #####
public function __construct() {
$this->socket = null;
$this->sftp = null;
$this->error = "";
}
public function Connect($host,$port = 22) {
if($host == "") return false;
$host = gethostbyname($host);
if( $this->socket = @ssh2_connect($host,$port) ) {
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) ) {
if(@ssh2_auth_password($this->socket,$user,$pass)) {
return true;
} else {
$this->error = 'Error #02: Autentication rejected by server!';
return false;
}
}
$this->error = 'Error #01: Server not found!';
return false;
}
public function SFTP_DownloadFile($uzak,$yerel) {
return ssh2_scp_recv($this->socket, $uzak, $yerel);
}
public function SFTP_UploadFile($dosya,$dosya2) {
return ssh2_scp_send($this->socket, $dosya, $dosya2, 0777);
}
public function OpenSFTP() {
if($this->sftp = ssh2_sftp($this->socket)) {
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->sftp = @ssh2_sftp($this->socket);
}
$filepath = 'ssh2.sftp://'.$this->sftp.'/'.$filepath;
if( !file_exists($filepath) ) { return false; } else {
$dosya = @fopen($filepath,'r');
$buffer = "";
while(!feof($dosya)) {
$buffer .= fread($dosya,filesize($filepath));
}
return $buffer;
}
}
public function SFTP_FileLink($filepath) {
if($filepath == "") return false;
if(!$this->sftp) {
$this->sftp = @ssh2_sftp($this->socket);
}
$filepath = 'ssh2.sftp://'.$this->sftp.'/'.$filepath;
return $filepath;
}
public function Disconnect() {
if(function_exists('ssh2_disconnect')) {
@ssh2_disconnect($this->socket);
} else {
@fclose($this->socket);
unset($this->socket);
}
return NULL;
}
public function Exec($cmd) {
$durum = @ssh2_exec($this->socket, $cmd);
@stream_set_blocking( $durum, true );
return $durum;
}
}
?>