1

私はディレクトリを読み取ろうとし、現在の日付から最後のファイルを取得したいと考えています。

ブラウザに URL を入力すると、ftp ディレクトリにあるすべてのファイルの結果が得られました。

だから私は、ftp-connection パラメータがまだ機能するという証拠を持っています。

ここに画像の説明を入力

次の関数を開始しようとすると、エラーが発生します

RecursiveDirectoryIterator::__construct( ftp://...@example.com:4242 ): ディレクトリを開けませんでした: 操作に失敗しました

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
    ]);
}

file_gets_content($url."filename.txt") を含むファイルで URL を開くと、エラーなしでコンテンツが取得されます。

SymfonyのFinderを正しく使用していないようです。

私の現在の Symfony は 4.1.4 で、キャッシュをクリアし、キャッシュ ファイルも手動で削除しました。

ヒントをありがとう

symfony-finder-component へのリンクは次のとおりです: https://symfony.com/doc/current/components/finder.html

Finder は PHP イテレータを使用するため、サポートされているプロトコルを使用して任意の URL を渡すことができます。

ドキュメントの FTP コードの一部を次に示します。

// 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/');
4

2 に答える 2