/** * Puts all files from the given folder. * * @param $path string Path from which to get the files * @param $targetPath string Path to save files to * @param $sourcePath string Source path on the import server * @param $recursive bool Set to true to explore file structure recursively * @return array List of transferred files */ public function putAllFiles($path, $targetPath, $sourcePath, $recursive = TRUE) { $transferredFiles = array(); // Get all files/folders in the current folder $files = $this->fromDriver->fileList($path); if ($this->extensionConfiguration['debug'] && count($files) > 2) { GeneralUtility::devLog('Files to handle', 'ftpimportexport', 0, $files); } foreach ($files as $aFile) { $pathInfo = pathinfo($aFile); $sourceFilename = $path . $aFile; $isDirectory = $this->fromDriver->directoryExists($sourceFilename); // If the current file is not a directory, download it and add it to the list of transferred files if (!$isDirectory && $this->isValidFile($aFile)) { $targetFilename = $targetPath . $sourcePath . $aFile; $result = $this->toDriver->put($sourceFilename, $targetFilename); if ($result) { // Keep list of transferred files for post-processing $transferredFiles[] = $aFile; } else { if ($this->extensionConfiguration['debug']) { GeneralUtility::devLog('Could not get file: ' . $aFile, 'ftpimportexport', 2); } } // If file is a directory, and not "." or ".." and "recursive" option was checked, get files for this folder } elseif ($recursive && $isDirectory && isset($pathInfo['basename']) && !in_array($pathInfo['basename'], array('.', '..'), true)) { $subfolderFiles = $this->putAllFiles($path . $aFile . '/', $targetPath, $sourcePath . $aFile . '/', $recursive); $transferredFiles = array_merge($transferredFiles, $subfolderFiles); } } return $transferredFiles; }