Пример #1
0
 /**
  * @return string
  */
 public function getId()
 {
     // FIXME: double slash to keep compatible with the old storage ids,
     // failure to do so will lead to creation of a new storage id and
     // loss of shares from the storage
     return 'smb::' . $this->server->getUser() . '@' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root;
 }
Пример #2
0
 private function buildUrl($path)
 {
     $this->verifyPath($path);
     $url = sprintf('smb://%s/%s', $this->server->getHost(), $this->name);
     if ($path) {
         $path = trim($path, '/');
         $url .= '/';
         $url .= implode('/', array_map('rawurlencode', explode('/', $path)));
     }
     return $url;
 }
Пример #3
0
 /**
  * Open a writable stream to a remote file
  *
  * @param string $target
  * @return resource a write only stream to upload a remote file
  *
  * @throws \Icewind\SMB\Exception\NotFoundException
  * @throws \Icewind\SMB\Exception\InvalidTypeException
  */
 public function write($target)
 {
     $target = $this->escapePath($target);
     // close the single quote, open a double quote where we put the single quote...
     $target = str_replace('\'', '\'"\'"\'', $target);
     // since returned stream is closed by the caller we need to create a new instance
     // since we can't re-use the same file descriptor over multiple calls
     $command = sprintf('%s --authentication-file=/proc/self/fd/3 //%s/%s -c \'put /proc/self/fd/4 %s\'', Server::CLIENT, $this->server->getHost(), $this->name, $target);
     $connection = new RawConnection($command);
     $connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
     $fh = $connection->getFileInputStream();
     // use a close callback to ensure the upload is finished before continuing
     // this also serves as a way to keep the connection in scope
     return CallbackWrapper::wrap($fh, null, null, function () use($connection) {
         $connection->close(false);
         // dont terminate, give the upload some time
     });
 }
Пример #4
0
 /**
  * Open a writable stream to a remote file
  *
  * @param string $target
  * @return resource a write only stream to upload a remote file
  *
  * @throws \Icewind\SMB\Exception\NotFoundException
  * @throws \Icewind\SMB\Exception\InvalidTypeException
  */
 public function write($target)
 {
     $target = $this->escapePath($target);
     // since returned stream is closed by the caller we need to create a new instance
     // since we can't re-use the same file descriptor over multiple calls
     $workgroupArgument = $this->server->getWorkgroup() ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
     $command = sprintf('%s %s --authentication-file=%s %s', $this->system->getSmbclientPath(), $workgroupArgument, System::getFD(3), escapeshellarg('//' . $this->server->getHost() . '/' . $this->name));
     $connection = new Connection($command);
     $connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
     $fh = $connection->getFileInputStream();
     $connection->write('put ' . System::getFD(4) . ' ' . $target);
     $connection->write('exit');
     // use a close callback to ensure the upload is finished before continuing
     // this also serves as a way to keep the connection in scope
     return CallbackWrapper::wrap($fh, null, null, function () use($connection, $target) {
         $connection->close(false);
         // dont terminate, give the upload some time
     });
 }
Пример #5
0
 /**
  * @return string
  */
 public function getId()
 {
     return 'smb::' . $this->server->getUser() . '@' . $this->server->getHost() . '/' . $this->share->getName() . '/' . $this->root;
 }