HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //proc/1526/task/1526/cwd/shoetique/wp-content/plugins/Ipis-product-Import/sftp_class.php
<?php 

class SFTPClient
{

    private $connection;
    private $sftp;

    public function __construct($host, $port=22){
        $this->connection = @ssh2_connect($host, $port);

        if (!$this->connection){
            throw new Exception("Failed to connect to ${host} on port ${port}.");
        }
    }

    public function auth_password($username, $password){
        if (!@ssh2_auth_password($this->connection, $username, $password)){
            throw new Exception("Failed to authenticate with username ${username} and password.");
        }

        $this->sftp = @ssh2_sftp($this->connection);
        if (!$this->sftp){
            throw new Exception("Could not initialize SFTP subsystem");
        }
    }

    public function get_latest_file($dir = "."){
        $sftp = $this->sftp;
        $realPath = ssh2_sftp_realpath($sftp, $dir);
        $dir = "ssh2.sftp://$sftp$realPath";
        $tempArray = array();

        if(is_dir($dir)){
            if($dh = opendir($dir)){
                while(($file = readdir($dh)) !== false){

                    if(strpos($file, 'WEBShop.cjenik.') === false){
                        continue;
                    }

                    $tempArray[] = $file;
                }

                closedir($dh);
            }
        } else {
            throw new Exception("The selected directory does not exist");
        }

        arsort($tempArray);
        $latest_file = array_shift($tempArray);

        return $dir . '/' . $latest_file;
    }

    public function change_dir($file){

        if (!$file){
            throw new Exception("Could not find file: $file");
        }
        
        $sftp = $this->sftp;
        $realPath = ssh2_sftp_realpath($sftp, "./imported");
        $dir = "ssh2.sftp://$sftp$realPath";
        $fileName = end(explode("/", $file));

        $stream = @fopen($file, 'r');
        $newFile = @fopen($dir . "/" . $fileName . '_imported', 'w');

        if (!$stream){
            throw new Exception("Could not open file: $file");
        }

        stream_copy_to_stream($stream, $newFile);

        @fclose($stream);
        @fclose($newFile);
    }

    public function delete_file($file){

        if (!$file){
            throw new Exception("Could not find file: $file");
        }

        $sftp = $this->sftp;
        $realpath = ssh2_sftp_realpath($sftp, $file);
        unlink("ssh2.sftp://$sftp$realpath");
      }

    public function disconnect(){
        @ssh2_disconnect($this->connection);
    }

}

?>