Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function run($command, $callback = null)
 {
     $this->checkConnection();
     $result = $this->sftp->exec($command, $callback);
     if ($this->sftp->getExitStatus() !== 0) {
         $output = $this->sftp->getStdError() ?: $result;
         throw new \RuntimeException($output);
     }
     return $result;
 }
Esempio n. 2
0
 public function remove($path, $recursive = true)
 {
     if (false === $this->isConnected()) {
         $this->connectAndLogin();
     }
     $this->dispatcher->dispatch(TransporterEvents::TRANSPORTER_REMOVE, new TransporterEvent($this, array('path' => $path)));
     $recursiveFlag = $recursive ? 'r' : '';
     $success = $this->sftp->exec(sprintf("rm -{$recursiveFlag}f %s", escapeshellarg($path)));
     if (false === $success) {
         $errors = (array) $this->sftp->getErrors();
         throw new \RuntimeException('Something went wrong: ' . "\n" . implode("\n", $errors));
     } elseif ($error = $this->sftp->getStdError()) {
         throw new \RuntimeException('Something went wrong: ' . "\n" . $error);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function executeCommand($command, array $arguments = array())
 {
     if ($this->isConnected()) {
         $this->connection->enableQuietMode();
         $this->connection->setTimeout(0);
         if (empty($arguments) === false) {
             $command = ProcessUtility::escapeArguments($arguments, $command);
         }
         if (isset($this->connection->server_channels[SFTP::CHANNEL_SHELL]) === false) {
             $this->connection->read($this->getShellPromptRegex(), SFTP::READ_REGEX);
         }
         $this->connection->write($command . "\n");
         $output = $this->getFilteredOutput($this->connection->read($this->getShellPromptRegex(), SFTP::READ_REGEX), $command);
         $this->connection->write("echo \$?\n");
         $exitCode = intval($this->getFilteredOutput($this->connection->read($this->getShellPromptRegex(), SFTP::READ_REGEX), 'echo $?'));
         $errorOutput = strval($this->connection->getStdError());
         $this->connection->disableQuietMode();
         return new ProcessExecutionResult($exitCode, $output, $errorOutput);
     }
     return new ProcessExecutionResult(126, '', "Connection adapter not connected.\n");
 }