/** * @depends testPutGetString * @param \phpseclib\Net\SCP $scp */ public function testGetFile($scp) { $localFilename = $this->createTempFile(); $this->assertTrue($scp->get(self::$remoteFile, $localFilename), 'Failed asserting that get() into file was successful.'); // TODO: Address https://github.com/phpseclib/phpseclib/issues/146 $this->assertContains(filesize($localFilename), array(self::$exampleDataLength, self::$exampleDataLength + 1), 'Failed asserting that filesize matches expected data size.'); $this->assertContains(file_get_contents($localFilename), array(self::$exampleData, self::$exampleData . ""), 'Failed asserting that file content matches expected content.'); }
/** * Create new backup files * Auto remove old backup files (only files created by this script wil be removed) * Download backup files from routerboard via SCP * Save files to the desination * * @param string $addr IP address * @param string $port * @param string $filename * @param string $folder * @param string $identity of the router board * @return boolean */ public function getBackupFile($addr, $port, $filename, $folder, $identity) { $user = $this->config['routerboard']['backupuser']; $msg = 'Connect to the: ' . $user . "@" . $addr . ":" . $port . ' has been '; if ($ssh = $this->sshConnect($addr, $port, true)) { $this->logger->log($msg . 'successfully.'); // remove old backup files $ssh->exec('file remove [/file find where name~"' . $user . '-"]'); // create new backups $ssh->exec('system backup save name=' . $filename); $ssh->exec('export compact file=' . $filename); // download and save new backup files $scp = new SCP($ssh); $bfs = new BackupFilesystem($this->config, $this->logger); if ($bfs->saveBackupFile($addr, $scp->get($filename . '.backup'), $folder, $filename, 'backup', $identity) && $bfs->saveBackupFile($addr, $scp->get($filename . '.rsc'), $folder, $filename, 'rsc', $identity)) { $this->sshDisconnect($ssh); return true; } $this->sshDisconnect($ssh); return false; } $this->logger->log($msg . 'fails!', $this->logger->setError()); return false; }