• 11-02-2025, 03:57:56
    #1
    merhaba deepseek chatgpt den convert yapmaya çalıştığımda hiç bir şekilde çalışmadı alttaki ogcp_ssh2 classı değişken isimleri fonksiyon isimleri herşeyi aynı olacak şekilde sadece ssh2 eklentisinden ssh2_connect ssh2_sftp den phpseclibe çevirebilcek varmı ?
    <?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;
            }
        }
    ?>
    • bxyweb
    [ARG:2 UNDEFINED] bunu beğendi.
    1 kişi bunu beğendi.
  • 11-02-2025, 04:00:03
    #2
    <?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);
        }
    }
    ?>
    • gturkmen222
    [ARG:2 UNDEFINED] bunu beğendi.
    1 kişi bunu beğendi.
  • 11-02-2025, 04:03:19
    #3
    Misafir adlı üyeden alıntı: mesajı görüntüle
    <?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);
        }
    }
    ?>
    teşekkür ederim bu şimdi sorunsuz çalışır mı ?
    • bxyweb
    [ARG:2 UNDEFINED] bunu beğendi.
    1 kişi bunu beğendi.
  • 11-02-2025, 04:06:59
    #4
    Misafir adlı üyeden alıntı: mesajı görüntüle
    teşekkür ederim bu şimdi sorunsuz çalışır mı ?
    dene hocam bilgilendirirsen ekran paylaşabileceğin yerden yardımcı olurum
  • 11-02-2025, 04:13:31
    #5
    ssh kütüphanesi'ni import etmemişsin hocam kod'da yok
  • 11-02-2025, 04:14:42
    #6
    Kara adlı üyeden alıntı: mesajı görüntüle
    ssh kütüphanesi'ni import etmemişsin hocam kod'da yok
    yok hocam benim attığım normalde php ssh2 eklentili ama ben phpseclib çeviri istedim arkadaş attı saolsun şimdi phpseclib kütüphanesini composer edip deneyeceğim
  • 11-02-2025, 04:30:58
    #7
    Misafir; teşekkür ederim sıkıntısız çalıştı allah razı olsun @Kara; sıkıntısız çalıştı
  • 11-02-2025, 12:12:59
    #8
    Misafir adlı üyeden alıntı: mesajı görüntüle
    <?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);
        }
    }
    ?>
    <?php
    require 'vendor/autoload.php';
    
    use phpseclib3\Net\SSH2;
    use phpseclib3\Net\SFTP;
    
    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;
            $this->ssh = new SSH2($host, $port);
            return true;
        }
    
        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 OpenSFTP() {
            if (!$this->ssh) return false;
            $this->sftp = new SFTP($this->ssh->getHost());
            return $this->sftp->login($this->ssh->getUsername(), $this->ssh->getPassword());
        }
    
        public function SFTP_DownloadFile($remote, $local) {
            if (!$this->sftp) return false;
            return file_put_contents($local, $this->sftp->get($remote));
        }
    
        public function SFTP_UploadFile($local, $remote) {
            if (!$this->sftp) return false;
            return $this->sftp->put($remote, file_get_contents($local));
        }
    
        public function SFTP_ReadFile($filepath) {
            if (!$this->sftp) return false;
            return $this->sftp->get($filepath);
        }
    
        public function Exec($cmd) {
            if (!$this->ssh) return false;
            return $this->ssh->exec($cmd);
        }
    
        public function Disconnect() {
            $this->ssh = null;
            $this->sftp = null;
        }
    }
    ?>
    Birde bunu deneyin
  • 11-02-2025, 12:15:59
    #9
    Aryax adlı üyeden alıntı: mesajı görüntüle
    <?php
    require 'vendor/autoload.php';
    
    use phpseclib3\Net\SSH2;
    use phpseclib3\Net\SFTP;
    
    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;
            $this->ssh = new SSH2($host, $port);
            return true;
        }
    
        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 OpenSFTP() {
            if (!$this->ssh) return false;
            $this->sftp = new SFTP($this->ssh->getHost());
            return $this->sftp->login($this->ssh->getUsername(), $this->ssh->getPassword());
        }
    
        public function SFTP_DownloadFile($remote, $local) {
            if (!$this->sftp) return false;
            return file_put_contents($local, $this->sftp->get($remote));
        }
    
        public function SFTP_UploadFile($local, $remote) {
            if (!$this->sftp) return false;
            return $this->sftp->put($remote, file_get_contents($local));
        }
    
        public function SFTP_ReadFile($filepath) {
            if (!$this->sftp) return false;
            return $this->sftp->get($filepath);
        }
    
        public function Exec($cmd) {
            if (!$this->ssh) return false;
            return $this->ssh->exec($cmd);
        }
    
        public function Disconnect() {
            $this->ssh = null;
            $this->sftp = null;
        }
    }
    ?>
    Birde bunu deneyin
    sftpfilelink eksik onuda eklermisiniz