@param string $container
@param string $dest_path
@param string $src_container
@param string $src_path
@param bool   $check_exist

@throws \Exception
@throws NotFoundException
@throws BadRequestException
@return void
339830
public function copyFile($container, $dest_path, $src_container, $src_path, $check_exist = false)
    {
        // does this file already exist?
        if (!$this->fileExists($src_container, $src_path)) {
            throw new NotFoundException("File '$src_path' does not exist.");
        }
        if ($this->fileExists($container, $dest_path)) {
            if (($check_exist)) {
                throw new BadRequestException("File '$dest_path' already exists.");
            }
        }
        // does this file's parent folder exist?
        $parent = FileUtilities::getParentFolder($dest_path);
        if (!empty($parent) && (!$this->folderExists($container, $parent))) {
            throw new NotFoundException("Folder '$parent' does not exist.");
        }

        // create the file
        $this->checkContainerForWrite($container); // need to be able to write to storage
        $this->copyBlob($container, $dest_path, $src_container, $src_path);
    }
623667
protected function copyFileWithDirsCreating($src, $dest)
    {
        $dirPathOfDestFile = dirname($dest);

        if (! File::exists($dirPathOfDestFile)) {
            File::makeDirectory($dirPathOfDestFile, 0755, true);
        }

        if (! File::exists($dest)) {
            File::copy($src, $dest);
        }
    }
114080
public function getFileContent($container, $path, $local_file = '', $content_as_base = true)
    {
        if (!$this->containerExists($container) || !$this->blobExists($container, $path)) {
            throw new NotFoundException("File '$path' does not exist in storage.");
        }
        if (!empty($local_file)) {
            // write to local or temp file
            $this->getBlobAsFile($container, $path, $local_file);

            return '';
        } else {
            // get content as raw or encoded as base64 for transport
            $data = $this->getBlobData($container, $path);
            if ($content_as_base) {
                $data = base64_encode($data);
            }

            return $data;
        }
    }
680518
private static function removeContainerFromPath($container, $path)
    {
        if (empty($container)) {
            return $path;
        }
        $container = FileUtilities::fixFolderPath($container);

        return substr($path, strlen($container));
    }
958696
public function put($src, $dest){
		if ( file_exists($src) &&
            ($dest = $this->checkFilePath($dest)) &&
            ftp_put($this->cn,$dest,$src,FTP_BINARY) ){
      return true;
		}
		return false;
	}
636853
public function streamBlob($container, $name, $params = [])
    {
        $this->checkConnection();
        try {
            /** @var Container $container */
            $container = $this->blobConn->getContainer($container);
            if (empty($container)) {
                throw new \Exception("No container named '$container'");
            }

            $obj = $container->DataObject($name);

            header('Last-Modified: ' . $obj->getLastModified());
            header('Content-Type: ' . $obj->getContentType());
            header('Content-Length:' . $obj->getContentLength());

            $disposition =
                (isset($params['disposition']) && !empty($params['disposition'])) ? $params['disposition']
                    : 'inline';

            header('Content-Disposition: ' . $disposition . '; filename="' . $name . '";');
            $index = 0;
            $size = (integer)$obj->getContentLength();
            $chunk = \Config::get('df.file_chunk_size');
            ob_clean();

            while ($index < $size) {
                $header = ['Range' => 'bytes=' . $index . '-' . ($index + $chunk - 1)];
                /** @var \Guzzle\Http\Message\RequestInterface $result */
                $request = $container->getService()->getClient()->get($obj->getUrl(), $header);
                /** @var \Guzzle\Http\Message\Response $result */
                $result = $request->send();
                $length = $result->getContentLength();
                $index += $length;
                flush();
                echo $result->getBody();
            }
        } catch (\Exception $ex) {
            static::handleGuzzleException($ex);
            if ($ex instanceof ObjFetchError) {
                $code = HttpStatusCodes::HTTP_NOT_FOUND;
                $status_header = "HTTP/1.1 $code";
                header($status_header);
                header('Content-Type: text/html');
                echo 'Failed to stream/download file. File ' . $name . ' was not found. ' . $ex->getMessage();
            } else {
                throw new DfException('Failed to stream blob: ' . $ex->getMessage());
            }
        }
    }
87883
public function containerExists($container)
    {
        $this->checkConnection();
        try {
            $this->blobConn->getContainerProperties($container);

            return true;
        } catch (\Exception $ex) {
            if (false === stripos($ex->getMessage(), 'does not exist')) {
                throw $ex;
            }
        }

        return false;
    }
704196
public function addMapping(string $src, string $dest): void
	{
		$this->mapper[$src] = $dest;
	}
1194449
public function createContainer($properties = [], $check_exist = false)
    {
        $container = array_get($properties, 'name', array_get($properties, 'path'));
        if (empty($container)) {
            throw new BadRequestException('No name found for container in create request.');
        }
        // does this folder already exist?
        if ($this->folderExists($container, '')) {
            if ($check_exist) {
                throw new BadRequestException("Container '$container' already exists.");
            }
        } else {
            // create the container
            $dir = static::addContainerToName($container, '');

            if (!mkdir($dir, 0777, true)) {
                throw new InternalServerErrorException('Failed to create container.');
            }
        }

        return ['name' => $container, 'path' => $container];

//            $properties = (empty($properties)) ? '' : json_encode($properties);
//            $result = file_put_contents($key, $properties);
//            if (false === $result) {
//                throw new InternalServerErrorException('Failed to create container properties.');
//            }
    }
44994
public function getFileProperties($container, $path, $include_content = false, $content_as_base = true)
    {
        if (!$this->fileExists($container, $path)) {
            throw new NotFoundException("File '$path' does not exist in storage.");
        }
        $file = static::addContainerToName($container, $path);
        $shortName = FileUtilities::getNameFromPath($path);
        $ext = FileUtilities::getFileExtension($file);
        $temp = stat($file);
        $data = [
            'path'           => $path,
            'name'           => $shortName,
            'content_type'   => FileUtilities::determineContentType($ext, '', $file),
            'last_modified'  => gmdate('D, d M Y H:i:s \G\M\T', array_get($temp, 'mtime', 0)),
            'content_length' => array_get($temp, 'size', 0)
        ];
        if ($include_content) {
            $contents = file_get_contents($file);
            if (false === $contents) {
                throw new InternalServerErrorException('Failed to retrieve file properties.');
            }
            if ($content_as_base) {
                $contents = base64_encode($contents);
            }
            $data['content'] = $contents;
        }

        return $data;
    }
775685
public function rsyncCommand($src, $dest, array $rsyncOptions)
    {
        if (strpos($src, ':') !== false) {
            $site_env_id = $this->getSiteEnvIdFromPath($src);
            $src = $this->removeSiteEnvIdFromPath($src);
        } else {
            $site_env_id = $this->getSiteEnvIdFromPath($dest);
            $dest = $this->removeSiteEnvIdFromPath($dest);
        }

        return $this->rsync($site_env_id, $src, $dest, $rsyncOptions);
    }
587821
protected function copy($src, $dest, &$errors = 0, &$success = 0)
    {
        if (is_file($src)) {

            if (copy($src, $dest)) {
                $success++;
                return true;
            }

            $errors++;
            return false;
        }

        if (!is_dir($dest) && !mkdir($dest)) {
            $errors++;
            return false;
        }

        foreach (new DirectoryIterator($src) as $file) {

            $result = null;
            $copyto = "$dest/" . $file->getBasename();

            if ($file->isFile() || (!$file->isDot() && $file->isDir())) {
                $result = $this->copy($file->getRealPath(), $copyto, $errors, $success);
            }

            if (!isset($result)) {
                continue;
            }

            if ($result) {
                $success++;
            } else {
                $errors++;
            }
        }

        $success++;
        return true;
    }
692922
public function permissionForm(Container $container): void
	{
		/* @var $container IContainer */
		$container->addSelectUntranslated('role', 'cms.permissions.role')
			->setItems($this->orm->aclRoles->fetchPairs($this->viewSuperadmin));
		$container->addMultiSelectUntranslated('resource', 'cms.permissions.resource')
			->setItems($this->orm->aclResources->fetchPairsByResourceName());
		$container->addSelect('privilege', 'cms.permissions.privilege', $this->privileges);
		$container->addSelect('allowed', 'default.state', $this->access);
	}
60304
public function copy($src, $dest)
    {
        if (is_dir($src)) {
            $this->ensureDir($dest);
            $files = scandir($src);
            foreach ($files as $file) {
                if ($file !== '.' && $file !== '..') {
                    $this->copy($src . '/' . $file, $dest . '/' . $file);
                }
            }
        } else {
            $this->ensureDir(dirname($dest));

            copy($src, $dest);
        }
    }
458280
public function fileExists($containerName, $fileName, $relativePath)
    {
        return $this->fileUploadFacade->fileExists($containerName, $fileName, $relativePath);
    }
416470
public function createFolder($container, $path, $is_public = true, $properties = [], $check_exist = true)
    {
        if (empty($path)) {
            throw new BadRequestException("Invalid empty path.");
        }

        // does this folder already exist?
        $path = FileUtilities::fixFolderPath($path);
        if ($this->folderExists($container, $path)) {
            if ($check_exist) {
                throw new BadRequestException("Folder '$path' already exists.");
            }

            return;
        }
        // does this folder's parent exist?
        $parent = FileUtilities::getParentFolder($path);
        if (!empty($parent) && (!$this->folderExists($container, $parent))) {
            if ($check_exist) {
                throw new NotFoundException("Folder '$parent' does not exist.");
            }
            $this->createFolder($container, $parent, $is_public, $properties, false);
        }

        // create the folder
        $this->checkContainerForWrite($container); // need to be able to write to storage
        $properties = (empty($properties)) ? '' : json_encode($properties);
        $this->putBlobData($container, $path, $properties);
    }
1060131
public static function mirror($source, $dest, PackageEvent $event)
    {
        if (realpath($source) === realpath($dest)) {
            return;
        }
        $fs = new Filesystem();
        try {
            $fs->mirror($source, $dest);
        } catch (IOException $e) {
            $event->getIO()->writeError(sprintf('Mirroring %s to %s failed:', $source, $dest));
            $event->getIO()->writeError($e->getMessage());
        }
    }