Last active
June 27, 2024 09:07
-
-
Save rtconner/40b415073378da28b2bf to your computer and use it in GitHub Desktop.
Provider so you can add a 'sftp' connection in Laravel 5 filesystems.php - "Call to undefined method League\Flysystem\Filesystem::createSftpDriver"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use League\Flysystem\Sftp\SftpAdapter; | |
use Storage; | |
use League\Flysystem\Filesystem; | |
use Illuminate\Support\ServiceProvider; | |
/** | |
* Class SftpServiceProvider | |
* @package App\Providers | |
* | |
* composer require league/flysystem-sftp "~1.0" | |
* | |
* Add this file to the Providers directory and update your app.php config | |
* | |
* Sample config to put in filesystems.php config: | |
* 'sftp' => [ | |
* 'driver' => 'sftp', | |
* 'host' => 'example.com', | |
* 'port' => 22, | |
* 'username' => 'username', | |
* 'password' => 'password', | |
* 'privateKey' => 'path/to/or/contents/of/privatekey', | |
* // 'root' => '/path/to/root', | |
* // 'timeout' => 10, | |
* // 'directoryPerm' => 0755 | |
* ], | |
*/ | |
class SftpServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Perform post-registration booting of services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
Storage::extend('sftp', function($app, $config) { | |
unset($config['driver']); | |
foreach($config as $key => $value) { | |
if(!strlen($value)) { | |
unset($config[$key]); | |
} | |
} | |
$adapter = new SftpAdapter($config); | |
return new Filesystem($adapter); | |
}); | |
} | |
/** | |
* Register bindings in the container. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You might be able to get away with doing
$config = array_filter($config);
would you not?