예제 #1
0
 /**
  * Download a remote file
  *
  * @param string $source remove file
  * @param string $target local file
  * @return bool
  *
  * @throws \Icewind\SMB\Exception\NotFoundException
  * @throws \Icewind\SMB\Exception\InvalidTypeException
  * @throws \Icewind\SMB\Exception\InvalidPathException
  * @throws \Icewind\SMB\Exception\InvalidResourceException
  */
 public function get($source, $target)
 {
     if (!$target) {
         throw new InvalidPathException('Invalid target path: Filename cannot be empty');
     }
     $targetHandle = @fopen($target, 'wb');
     if (!$targetHandle) {
         $error = error_get_last();
         if (is_array($error)) {
             $reason = $error['message'];
         } else {
             $reason = 'Unknown error';
         }
         throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing: ' . $reason);
     }
     $this->connect();
     $sourceHandle = $this->state->open($this->buildUrl($source), 'r');
     if (!$sourceHandle) {
         fclose($targetHandle);
         throw new InvalidResourceException('Failed opening remote file "' . $source . '" for reading');
     }
     while ($data = $this->state->read($sourceHandle, 4096)) {
         fwrite($targetHandle, $data);
     }
     $this->state->close($sourceHandle);
     return true;
 }
예제 #2
0
 /**
  * Download a remote file
  *
  * @param string $source remove file
  * @param string $target local file
  * @return bool
  *
  * @throws \Icewind\SMB\Exception\NotFoundException
  * @throws \Icewind\SMB\Exception\InvalidTypeException
  */
 public function get($source, $target)
 {
     $this->connect();
     $sourceHandle = $this->state->open($this->buildUrl($source), 'r');
     $targetHandle = fopen($target, 'wb');
     while ($data = $this->state->read($sourceHandle, 4096)) {
         fwrite($targetHandle, $data);
     }
     $this->state->close($sourceHandle);
     return true;
 }
예제 #3
0
 public function stream_close()
 {
     return $this->state->close($this->handle);
 }