I try to read the dir and wanna get the last files from the current date.
When I put the url in the browser I got a result of all the files, which are in the ftp-directory.
So I have the proof, that the ftp-connectionparameter still works.
When I try to start the following function, then I get the error
RecursiveDirectoryIterator::__construct(ftp://...@example.com:4242): failed to open dir: operation failed
Here is the Exception from symfony:
/**
* @Route("/download", name="getfile")
*/
public function getFileWithFtp()
{
$host = "example.com";
$username = "username";
$userpass = "userpass";
$port = 4242;
$url = 'ftp://' . $username . ':' . $userpass . '@' . $host . ':' . $port .'/';
$datum = date('Y-m-d');
$finder = new Finder();
$iterator = $finder
->files()
->in($url)
->name('*BEHWN.TXT')
->date($datum);
$anzahl = count($iterator);
return $this->render('ftp/index.html.twig', [
'controller_name' => 'FtpController',
'url' => $url,
'anzahl' => $anzahl
]);
}
WHen i open the url with the file with file_gets_content($url."filename.txt"), then i get the content without error.
Only it seems that I dont use the Finder from Symfony not correct.
My current Symfony is 4.1.4 and I had cleared the caches and also i deleted the cache-files manually.
Thanks for every tipp
Here is the link to the symfony-finder-component: https://symfony.com/doc/current/components/finder.html
As the Finder uses PHP iterators, you can pass any URL with a supported protocol:
Here is the part of the FTP code from the documentation:
// always add a trailing slash when looking for in the FTP root dir
$finder->in('ftp://example.com/');
// you can also look for in a FTP directory
$finder->in('ftp://example.com/pub/');