• 11-02-2025, 05:27:44
    #1
    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);
        }
    }
    ?>
  • 11-02-2025, 05:30:07
    #2
    Misafir;
    senin attığın buydu pardon yardım edebilirmisin

    <?php
    use phpseclib3\Net\SSH2;
    use phpseclib3\Net\SFTP;
     
    require 'vendor/autoload.php';
     
    class ogcp_ssh2 {
        private $ssh;
        private $sftp;
        private $error;
     
        public function __construct() {
            $this->ssh = null;
            $this->sftp = null;
            $this->error = "";
        }
     
        public function Connect($host, $port = 22) {
            if ($host == "") return false;
            $host = gethostbyname($host);
             
            $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)) {
                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->ssh->getServerHost(), $this->ssh->getPort());
                $this->sftp->login($this->ssh->getUsername(), $this->ssh->getPassword());
            }
            return $this->sftp->get($remote, $local);
        }
     
        public function SFTP_UploadFile($local, $remote) {
            if (!$this->sftp) {
                $this->sftp = new SFTP($this->ssh->getServerHost(), $this->ssh->getPort());
                $this->sftp->login($this->ssh->getUsername(), $this->ssh->getPassword());
            }
            return $this->sftp->put($remote, $local, SFTP::SOURCE_LOCAL_FILE);
        }
     
        public function OpenSFTP() {
            $this->sftp = new SFTP($this->ssh->getServerHost(), $this->ssh->getPort());
            if ($this->sftp->login($this->ssh->getUsername(), $this->ssh->getPassword())) {
                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);
        }
    }
    ?>
  • 11-02-2025, 06:03:04
    #3
    ş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);
        }
    }
    ?>
  • 11-02-2025, 06:18:09
    #4
    victories adlı üyeden alıntı: mesajı görüntüle
    ş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);
        }
    }
    ?>
    yine olmadı
  • 11-02-2025, 06:20:42
    #5
    victories adlı üyeden alıntı: mesajı görüntüle
    ş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;
            }
        }
    ?>
  • 11-02-2025, 06:22:41
    #6
    Yine aynı hatayı mı aldınız, mümkün değil

    getServerHost(), getUsername() ve getPassword() phpseclib3 te yok, şu anda başka bir hata alıyor olmalısınız, onu yazarsanız bakalım.

    Edit: kendi kendimi alıntılamışım.
  • 11-02-2025, 06:25:01
    #7
    victories adlı üyeden alıntı: mesajı görüntüle
    ş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);
        }
    }
    ?>
    victories adlı üyeden alıntı: mesajı görüntüle
    Yine aynı hatayı mı aldınız, mümkün değil

    getServerHost(), getUsername() ve getPassword() phpseclib3 te yok, şu anda başka bir hata alıyor olmalısınız, onu yazarsanız bakalım.
    şuan hiç bir hata almadım error log yazmıyor hiç bir şekilde 2 inci defa yazdım size bakmadınız galiba ama şöyle ssh işlemi ve exec işlemi çalışıyor sadece sftp olan kısımlar çalışmıyor herhalde ssh2.sftp:// olmadığı için phpseclibe uyarlamak lazım galiba orjinali buydu ssh2 eklentili biraz oldu gibi ama

    <?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;
            }
        }
    ?>
  • 11-02-2025, 06:29:45
    #8
    Misafir adlı üyeden alıntı: mesajı görüntüle
    şuan hiç bir hata almadım error log yazmıyor hiç bir şekilde 2 inci defa yazdım size bakmadınız galiba ama şöyle ssh işlemi ve exec işlemi çalışıyor sadece sftp olan kısımlar çalışmıyor herhalde ssh2.sftp:// olmadığı için phpseclibe uyarlamak lazım galiba orjinali buydu ssh2 eklentili biraz oldu gibi ama

    <?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;
            }
        }
    ?>
    Şöyle hata ayıklama eklenmiş halini bir deneyin, çıkan hataya göre bakalım.

    <?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;
        private $debug = true; // Hata ayıklama modu
        
        private function logError($message, $function = '') {
            $timestamp = date('Y-m-d H:i:s');
            $logMessage = "[{$timestamp}] {$function}: {$message}\n";
            
            if($this->debug) {
                error_log($logMessage, 3, 'sftp_errors.log');
                $this->error = $message;
            }
        }
      
        public function __construct() {
            $this->ssh = null;
            $this->sftp = null;
            $this->error = "";
        }
    
        public function getLastError() {
            return $this->error;
        }
      
        public function Connect($host, $port = 22) {
            if ($host == "") {
                $this->logError("Boş host adresi", __FUNCTION__);
                return false;
            }
            
            try {
                $this->host = gethostbyname($host);
                $this->port = $port;
                
                $this->logError("Bağlantı deneniyor: {$this->host}:{$this->port}", __FUNCTION__);
                $this->ssh = new SSH2($this->host, $this->port);
                
                if ($this->ssh) {
                    $this->logError("SSH bağlantısı başarılı", __FUNCTION__);
                    return true;
                } else {
                    $this->logError("SSH bağlantısı başarısız", __FUNCTION__);
                    return false;
                }
            } catch (\Exception $e) {
                $this->logError("Bağlantı hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function ConnectwAuth($host, $port = 22, $user, $pass) {
            if ($host == "" || $user == "" || $pass == "") {
                $this->logError("Eksik parametreler: host, user veya pass boş olamaz", __FUNCTION__);
                return false;
            }
      
            $this->username = $user;
            $this->password = $pass;
      
            try {
                if ($this->Connect($host, $port)) {
                    $this->logError("Login deneniyor: {$user}@{$host}", __FUNCTION__);
                    if ($this->ssh->login($user, $pass)) {
                        $this->logError("Login başarılı", __FUNCTION__);
                        return true;
                    } else {
                        $this->logError("Authentication rejected by server", __FUNCTION__);
                        return false;
                    }
                }
                $this->logError("Sunucu bulunamadı", __FUNCTION__);
                return false;
            } catch (\Exception $e) {
                $this->logError("Login hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function SFTP_DownloadFile($remote, $local) {
            try {
                $this->logError("SFTP indirme başlatılıyor - Remote: {$remote}, Local: {$local}", __FUNCTION__);
                
                if (!$this->sftp) {
                    $this->logError("Yeni SFTP bağlantısı oluşturuluyor", __FUNCTION__);
                    $this->sftp = new SFTP($this->host, $this->port);
                    
                    if (!$this->sftp->login($this->username, $this->password)) {
                        $this->logError("SFTP login başarısız", __FUNCTION__);
                        return false;
                    }
                    $this->logError("SFTP login başarılı", __FUNCTION__);
                }
                
                // Dosyanın varlığını kontrol et
                if (!$this->sftp->file_exists($remote)) {
                    $this->logError("Uzak dosya bulunamadı: {$remote}", __FUNCTION__);
                    return false;
                }
                
                // Yerel dizinin yazılabilir olduğunu kontrol et
                $localDir = dirname($local);
                if (!is_writable($localDir)) {
                    $this->logError("Yerel dizin yazılabilir değil: {$localDir}", __FUNCTION__);
                    return false;
                }
                
                $result = $this->sftp->get($remote, $local);
                
                if ($result) {
                    $this->logError("Dosya başarıyla indirildi", __FUNCTION__);
                    return true;
                } else {
                    $this->logError("Dosya indirme başarısız", __FUNCTION__);
                    return false;
                }
            } catch (\Exception $e) {
                $this->logError("Dosya indirme hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function SFTP_UploadFile($local, $remote) {
            try {
                $this->logError("SFTP yükleme başlatılıyor - Local: {$local}, Remote: {$remote}", __FUNCTION__);
                
                if (!file_exists($local)) {
                    $this->logError("Yerel dosya bulunamadı: {$local}", __FUNCTION__);
                    return false;
                }
                
                if (!$this->sftp) {
                    $this->logError("Yeni SFTP bağlantısı oluşturuluyor", __FUNCTION__);
                    $this->sftp = new SFTP($this->host, $this->port);
                    
                    if (!$this->sftp->login($this->username, $this->password)) {
                        $this->logError("SFTP login başarısız", __FUNCTION__);
                        return false;
                    }
                    $this->logError("SFTP login başarılı", __FUNCTION__);
                }
                
                $result = $this->sftp->put($remote, $local, SFTP::SOURCE_LOCAL_FILE);
                
                if ($result) {
                    $this->logError("Dosya başarıyla yüklendi", __FUNCTION__);
                    return true;
                } else {
                    $this->logError("Dosya yükleme başarısız", __FUNCTION__);
                    return false;
                }
            } catch (\Exception $e) {
                $this->logError("Dosya yükleme hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function OpenSFTP() {
            try {
                $this->logError("SFTP bağlantısı açılıyor", __FUNCTION__);
                $this->sftp = new SFTP($this->host, $this->port);
                
                if ($this->sftp->login($this->username, $this->password)) {
                    $this->logError("SFTP bağlantısı başarılı", __FUNCTION__);
                    return true;
                } else {
                    $this->logError("SFTP bağlantısı reddedildi", __FUNCTION__);
                    return false;
                }
            } catch (\Exception $e) {
                $this->logError("SFTP bağlantı hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function SFTP_ReadFile($filepath) {
            try {
                if ($filepath == "") {
                    $this->logError("Dosya yolu boş olamaz", __FUNCTION__);
                    return false;
                }
                
                if (!$this->sftp) {
                    if (!$this->OpenSFTP()) {
                        return false;
                    }
                }
                
                if (!$this->sftp->file_exists($filepath)) {
                    $this->logError("Dosya bulunamadı: {$filepath}", __FUNCTION__);
                    return false;
                }
                
                $content = $this->sftp->get($filepath);
                if ($content === false) {
                    $this->logError("Dosya okuma başarısız: {$filepath}", __FUNCTION__);
                    return false;
                }
                
                return $content;
            } catch (\Exception $e) {
                $this->logError("Dosya okuma hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function Disconnect() {
            try {
                if ($this->ssh) {
                    $this->ssh->disconnect();
                    $this->logError("SSH bağlantısı kapatıldı", __FUNCTION__);
                }
                $this->sftp = null;
                $this->ssh = null;
                return true;
            } catch (\Exception $e) {
                $this->logError("Bağlantı kapatma hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function Exec($cmd) {
            try {
                $this->logError("Komut çalıştırılıyor: {$cmd}", __FUNCTION__);
                $result = $this->ssh->exec($cmd);
                $this->logError("Komut sonucu: {$result}", __FUNCTION__);
                return $result;
            } catch (\Exception $e) {
                $this->logError("Komut çalıştırma hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
    }
    ?>
  • 11-02-2025, 06:36:19
    #9
    victories adlı üyeden alıntı: mesajı görüntüle
    Şöyle hata ayıklama eklenmiş halini bir deneyin, çıkan hataya göre bakalım.

    <?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;
        private $debug = true; // Hata ayıklama modu
        
        private function logError($message, $function = '') {
            $timestamp = date('Y-m-d H:i:s');
            $logMessage = "[{$timestamp}] {$function}: {$message}\n";
            
            if($this->debug) {
                error_log($logMessage, 3, 'sftp_errors.log');
                $this->error = $message;
            }
        }
      
        public function __construct() {
            $this->ssh = null;
            $this->sftp = null;
            $this->error = "";
        }
    
        public function getLastError() {
            return $this->error;
        }
      
        public function Connect($host, $port = 22) {
            if ($host == "") {
                $this->logError("Boş host adresi", __FUNCTION__);
                return false;
            }
            
            try {
                $this->host = gethostbyname($host);
                $this->port = $port;
                
                $this->logError("Bağlantı deneniyor: {$this->host}:{$this->port}", __FUNCTION__);
                $this->ssh = new SSH2($this->host, $this->port);
                
                if ($this->ssh) {
                    $this->logError("SSH bağlantısı başarılı", __FUNCTION__);
                    return true;
                } else {
                    $this->logError("SSH bağlantısı başarısız", __FUNCTION__);
                    return false;
                }
            } catch (\Exception $e) {
                $this->logError("Bağlantı hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function ConnectwAuth($host, $port = 22, $user, $pass) {
            if ($host == "" || $user == "" || $pass == "") {
                $this->logError("Eksik parametreler: host, user veya pass boş olamaz", __FUNCTION__);
                return false;
            }
      
            $this->username = $user;
            $this->password = $pass;
      
            try {
                if ($this->Connect($host, $port)) {
                    $this->logError("Login deneniyor: {$user}@{$host}", __FUNCTION__);
                    if ($this->ssh->login($user, $pass)) {
                        $this->logError("Login başarılı", __FUNCTION__);
                        return true;
                    } else {
                        $this->logError("Authentication rejected by server", __FUNCTION__);
                        return false;
                    }
                }
                $this->logError("Sunucu bulunamadı", __FUNCTION__);
                return false;
            } catch (\Exception $e) {
                $this->logError("Login hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function SFTP_DownloadFile($remote, $local) {
            try {
                $this->logError("SFTP indirme başlatılıyor - Remote: {$remote}, Local: {$local}", __FUNCTION__);
                
                if (!$this->sftp) {
                    $this->logError("Yeni SFTP bağlantısı oluşturuluyor", __FUNCTION__);
                    $this->sftp = new SFTP($this->host, $this->port);
                    
                    if (!$this->sftp->login($this->username, $this->password)) {
                        $this->logError("SFTP login başarısız", __FUNCTION__);
                        return false;
                    }
                    $this->logError("SFTP login başarılı", __FUNCTION__);
                }
                
                // Dosyanın varlığını kontrol et
                if (!$this->sftp->file_exists($remote)) {
                    $this->logError("Uzak dosya bulunamadı: {$remote}", __FUNCTION__);
                    return false;
                }
                
                // Yerel dizinin yazılabilir olduğunu kontrol et
                $localDir = dirname($local);
                if (!is_writable($localDir)) {
                    $this->logError("Yerel dizin yazılabilir değil: {$localDir}", __FUNCTION__);
                    return false;
                }
                
                $result = $this->sftp->get($remote, $local);
                
                if ($result) {
                    $this->logError("Dosya başarıyla indirildi", __FUNCTION__);
                    return true;
                } else {
                    $this->logError("Dosya indirme başarısız", __FUNCTION__);
                    return false;
                }
            } catch (\Exception $e) {
                $this->logError("Dosya indirme hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function SFTP_UploadFile($local, $remote) {
            try {
                $this->logError("SFTP yükleme başlatılıyor - Local: {$local}, Remote: {$remote}", __FUNCTION__);
                
                if (!file_exists($local)) {
                    $this->logError("Yerel dosya bulunamadı: {$local}", __FUNCTION__);
                    return false;
                }
                
                if (!$this->sftp) {
                    $this->logError("Yeni SFTP bağlantısı oluşturuluyor", __FUNCTION__);
                    $this->sftp = new SFTP($this->host, $this->port);
                    
                    if (!$this->sftp->login($this->username, $this->password)) {
                        $this->logError("SFTP login başarısız", __FUNCTION__);
                        return false;
                    }
                    $this->logError("SFTP login başarılı", __FUNCTION__);
                }
                
                $result = $this->sftp->put($remote, $local, SFTP::SOURCE_LOCAL_FILE);
                
                if ($result) {
                    $this->logError("Dosya başarıyla yüklendi", __FUNCTION__);
                    return true;
                } else {
                    $this->logError("Dosya yükleme başarısız", __FUNCTION__);
                    return false;
                }
            } catch (\Exception $e) {
                $this->logError("Dosya yükleme hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function OpenSFTP() {
            try {
                $this->logError("SFTP bağlantısı açılıyor", __FUNCTION__);
                $this->sftp = new SFTP($this->host, $this->port);
                
                if ($this->sftp->login($this->username, $this->password)) {
                    $this->logError("SFTP bağlantısı başarılı", __FUNCTION__);
                    return true;
                } else {
                    $this->logError("SFTP bağlantısı reddedildi", __FUNCTION__);
                    return false;
                }
            } catch (\Exception $e) {
                $this->logError("SFTP bağlantı hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function SFTP_ReadFile($filepath) {
            try {
                if ($filepath == "") {
                    $this->logError("Dosya yolu boş olamaz", __FUNCTION__);
                    return false;
                }
                
                if (!$this->sftp) {
                    if (!$this->OpenSFTP()) {
                        return false;
                    }
                }
                
                if (!$this->sftp->file_exists($filepath)) {
                    $this->logError("Dosya bulunamadı: {$filepath}", __FUNCTION__);
                    return false;
                }
                
                $content = $this->sftp->get($filepath);
                if ($content === false) {
                    $this->logError("Dosya okuma başarısız: {$filepath}", __FUNCTION__);
                    return false;
                }
                
                return $content;
            } catch (\Exception $e) {
                $this->logError("Dosya okuma hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function Disconnect() {
            try {
                if ($this->ssh) {
                    $this->ssh->disconnect();
                    $this->logError("SSH bağlantısı kapatıldı", __FUNCTION__);
                }
                $this->sftp = null;
                $this->ssh = null;
                return true;
            } catch (\Exception $e) {
                $this->logError("Bağlantı kapatma hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
      
        public function Exec($cmd) {
            try {
                $this->logError("Komut çalıştırılıyor: {$cmd}", __FUNCTION__);
                $result = $this->ssh->exec($cmd);
                $this->logError("Komut sonucu: {$result}", __FUNCTION__);
                return $result;
            } catch (\Exception $e) {
                $this->logError("Komut çalıştırma hatası: " . $e->getMessage(), __FUNCTION__);
                return false;
            }
        }
    }
    ?>
    ekranda şuanda herhangi bir hata çıkmıyor ama error loga şunu yazdı [11-Feb-2025 06:35:01 Europe/Istanbul] PHP Fatal error: Uncaught Error: Call to undefined method ogcp_ssh2::SFTP_FileLink() in /home/oyuncul2/public_html/page_func/Eklenti_Kontrol.php:13 Stack trace: #0 /home/oyuncul2/public_html/index.php(119): require_once() #1 {main} thrown in /home/oyuncul2/public_html/page_func/Eklenti_Kontrol.php on line 13 [11-Feb-2025 06:35:34 Europe/Istanbul] PHP Fatal error: Uncaught Error: Call to undefined method ogcp_ssh2::SFTP_FileLink() in /home/oyuncul2/public_html/page_func/Eklenti_Kontrol.php:13 Stack trace: #0 /home/oyuncul2/public_html/index.php(119): require_once() #1 {main} thrown in /home/oyuncul2/public_html/page_func/Eklenti_Kontrol.php on line 13