Skip to content

Instantly share code, notes, and snippets.

@kamaroly
Forked from rtconner/SftpServiceProvider.php
Created June 17, 2016 08:46
Show Gist options
  • Save kamaroly/846187641f4030b3c0d13cc6112a0abf to your computer and use it in GitHub Desktop.
Save kamaroly/846187641f4030b3c0d13cc6112a0abf 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"
<?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