lundi 4 septembre 2023

Connecting to an SFTP using Storage in Laravel

I Stumbled upon (not sure if its unique) a very tricky situation , when I try to connect to an SFTP with invalid credentials or is not enabled.

The first time I try to connect to SFTP which is not available it throws me proper error message but If I try to reconnect to same SFTP within a minute or 2 it does not throw any exception, I tested the same via php artisan tinker of LARAVEL.

    function conectToSFTP()
    {
        $diskName = 'sftp_name';
        try {
            $disk = Storage::disk($diskName);
            $files = $disk->files('/');
            echo "connected to sftp";
        } catch (\Exception $e) {
            echo "Unable to connect to SFTP " . $e->getMessage();
        }
    }

enter image description here

How can I get proper error message second time as well. Due to some reason or based on some condition I have to call

Storage::disk($diskName);

twice.

I tried adding a time delay using

sleep(45);

but that didnt worked



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/KBZVkdm
via IFTTT

Aucun commentaire:

Enregistrer un commentaire