Skip to content

Commit

Permalink
Update SftpLoader.php
Browse files Browse the repository at this point in the history
Downloads the sftp stream to the local file and returns the file.
  • Loading branch information
Daniel-Ateles committed Dec 22, 2021
1 parent 9de77df commit 6ec2b1b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/DataSource/Loader/SftpLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use League\Flysystem\Local\LocalFilesystemAdapter;
use League\Flysystem\PhpseclibV2\SftpAdapter;
use League\Flysystem\PhpseclibV2\SftpConnectionProvider;
use Pimcore\Bundle\DataImporterBundle\Exception\InvalidConfigurationException;
Expand Down Expand Up @@ -83,12 +84,18 @@ public function loadData(): string
);

$filesystem = new Filesystem(new SftpAdapter($connectionProvider, '/'));
$filesystemLocal = new Filesystem(new LocalFilesystemAdapter('/'));
try {
$filesystem->copy($this->remotePath, $this->importFilePath);
$readStream = $filesystem->readStream($this->remotePath);
$filesystemLocal->writeStream($this->importFilePath, $readStream);

return $this->importFilePath;
} catch (FilesystemException $e) {
Logger::error($e);
throw new InvalidConfigurationException(sprintf('Could not copy from remote location `%s` to local tmp file `%s`', $loggingRemoteUrl, $this->importFilePath));
}

throw new \Exception(sprintf('Could not find any files to load in path `%s`', $this->remotePath));
}

public function cleanup(): void
Expand Down

0 comments on commit 6ec2b1b

Please sign in to comment.