I am using File Storage (https://laravel.com/docs/8.x/filesystem#introduction) to 'put' a file to a remote ftp server. Everything works great, however I would ideally like to check that I have a decent ftp connection first before uploading, as the credentials are entered via a form and may be invalid occasionally. Could anyone help me understand how this could be achieved?
// configure ftp
$ftp = Storage::createFtpDriver([
'driver' => 'ftp',
'host' => $web->server_ip,
'username' => $web->server_username,
'password' => $web->server_password,
'port' => 21,
'passive' => false,
'ignorePassiveAddress' => true,
]);
// if connection is good then
$ftp->put('/thankyou.jpg', Storage::disk('local')->get('image1.jpg'));
// else
// echo 'Something went wrong with the connection';
I tried the following however instead of catching the error and displaying my own message it is taking me to the laravel debug screen with message like the following:
League\Flysystem\ConnectionRuntimeException
Could not login with connection: ftp.xx.com::21, username: zxxx1
or
League\Flysystem\ConnectionRuntimeException
Could not connect to host: ftp.xxx.com, port:21
Any ideas how I can make it return my message to the screen?