Example #1
0
 /**
  * @return \SMBBundle\SMB\IShare[]
  *
  * @throws \SMBBundle\SMB\Exception\AuthenticationException
  * @throws \SMBBundle\SMB\Exception\InvalidHostException
  */
 public function listShares()
 {
     $workgroupArgument = $this->workgroup ? ' -W ' . escapeshellarg($this->workgroup) : '';
     $command = Server::CLIENT . $workgroupArgument . ' --authentication-file=/proc/self/fd/3' . ' -gL ' . escapeshellarg($this->getHost());
     $connection = new RawConnection($command);
     $connection->writeAuthentication($this->getUser(), $this->getPassword());
     $output = $connection->readAll();
     $line = $output[0];
     $line = rtrim($line, ')');
     if (substr($line, -23) === ErrorCodes::LogonFailure) {
         throw new AuthenticationException();
     }
     if (substr($line, -26) === ErrorCodes::BadHostName) {
         throw new InvalidHostException();
     }
     if (substr($line, -22) === ErrorCodes::Unsuccessful) {
         throw new InvalidHostException();
     }
     if (substr($line, -28) === ErrorCodes::ConnectionRefused) {
         throw new InvalidHostException();
     }
     $shareNames = array();
     foreach ($output as $line) {
         if (strpos($line, '|')) {
             list($type, $name, $description) = explode('|', $line);
             if (strtolower($type) === 'disk') {
                 $shareNames[$name] = $description;
             }
         }
     }
     $shares = array();
     foreach ($shareNames as $name => $description) {
         $shares[] = $this->getShare($name);
     }
     return $shares;
 }
Example #2
0
 public function close($terminate = true)
 {
     if (is_resource($this->getInputStream())) {
         $this->write('close' . PHP_EOL);
     }
     parent::close($terminate);
 }