Example #1
0
 private function sendBackup($source, $destination, $paramSource = array(), $paramDestination = array())
 {
     $this->view = false;
     $nas = new Ssh($paramDestination['hostname'], $paramDestination['port'], $paramDestination['login'], $paramDestination['passwd']);
     $nas->connect();
     $target_directory = pathinfo($destination)['dirname'];
     $line = $nas->exec("mkdir -p " . $target_directory);
     $pos = strpos($line, "Permission denied");
     if ($pos !== false) {
         throw new \Exception("\nPMACTRL-077 : Impossible to create the directory : '" . $target_directory . "'");
     }
     $mysql = new Ssh($paramSource['hostname'], 22, $paramSource['login'], $paramSource['passwd']);
     $mysql->connect(Ssh::DEBUG_ON);
     $mysql->openShell();
     sleep(1);
     $mysql->waitPrompt($buffer);
     sleep(1);
     $scp = "scp {$source} " . $paramDestination['login'] . "@" . $paramDestination['hostname'] . ":" . $target_directory;
     $mysql->shellCmd($scp);
     $ret = $mysql->waitPrompt($buffer, '\\?');
     if ($ret === Ssh::SSH_PROMPT_FOUND) {
         $mysql->shellCmd("yes");
     }
     $out = end(explode(PHP_EOL, $buffer));
     //set password
     $pos = strpos("password:"******">>><<<";
         $mysql->shellCmd($paramDestination['passwd']);
     } else {
         $mysql->waitPrompt($buffer, "password\\:\\s*\$");
         $mysql->shellCmd($paramDestination['passwd']);
     }
     $mysql->waitPrompt($buffer);
     $file = pathinfo($source)['basename'];
     $this->size_transfered = trim($nas->exec("du -s " . $target_directory . "/" . $file . " | awk '{ print \$1 }'"));
     $this->md5_transfered = trim($nas->exec("md5sum " . $target_directory . "/" . $file . " | awk '{ print \$1 }'"));
     unset($nas);
 }