<?php

include('../vendor/phpseclib/phpseclib/phpseclib/net/SFTP.php');

class Backup {

    public function backup() {
        $server['192.168.80.10'] = ['login' => 'admin', 'pwd' => ''];
        foreach ($server as $info => $values) {
            $sftp = new Net_SFTP($info);
            if ($return = !$sftp->login($values['login'], $values['pwd'])) {
                exit('sftp Login Failed');
            }
            $c = $sftp->exec('ls');
            $r = preg_split('/\s+/', $c);
            $ret = array();
            foreach ($r as $value) {
                if ((substr($value, (strlen($value) - 6), strlen($value)) == 'backup')) {
                    $ret[] = $value;
                }
            }
            if (!file_exists('C:/web/' . $info . '/')) {
                mkdir('C:/web/' . $info . '/', null, true);
            }
            foreach ($ret as $key => $value) {
                $sftp->get($value, 'C:/web/' . $info . '/' . $value);
            }
            return $return;
        }
    }

}

//
//$c = new Backup();
//$c->backup();
