/** * Open the SSH connection * * @param Plum\Server\ServerInterface $server */ protected function connect(ServerInterface $server) { $ssh = new Net_SSH2($server->getHost(), $server->getPort()); if (!$ssh->login($server->getUser(), $server->getPassword())) { throw new SshException(sprintf('Authorization failed for user "%s"', $server->getUser())); } $this->con = $ssh; }
/** * Open the SSH connection * * @param Plum\Server\ServerInterface $server */ protected function connect(ServerInterface $server) { if (false === function_exists('ssh2_connect')) { throw new \RuntimeException('The "ssh2_connect" function does not exist.'); } $con = ssh2_connect($server->getHost(), $server->getPort()); if (false === $con) { throw new SshException(sprintf('Cannot connect to server "%s"', $server->getHost())); } if (false === ssh2_auth_password($con, $server->getUser(), $server->getPassword())) { throw new SshException(sprintf('Authorization failed for user "%s"', $server->getUser())); } $this->con = $con; }
/** * {@inheritDoc} */ public function doDeploy(ServerInterface $server, array $options, $dryRun) { $rsyncOptions = isset($options['rsync_options']) ? $options['rsync_options'] : '-azC --force --delete --progress'; // Exclude file $excludeFile = null; if (isset($options['rsync_exclude'])) { $excludeFile = $options['rsync_exclude']; if (false === file_exists($excludeFile)) { throw new \InvalidArgumentException(sprintf('The exclude file "%s" does not exist.', $excludeFile)); } $excludeFile = realpath($excludeFile); } $exclude = ''; if (null !== $excludeFile) { $exclude = sprintf('--exclude-from \'%s\'', $excludeFile); } $ssh = ''; if (22 !== $server->getPort()) { $ssh = sprintf('-e "ssh -p%d"', $server->getPort()); } $login = sprintf('%s@%s:%s', $server->getUser(), $server->getHost(), $server->getDir()); $command = sprintf('rsync %s %s %s ./ %s %s', $dryRun ? "--dry-run" : "", $rsyncOptions, $ssh, $login, $exclude); system($command); }