2017-09-26 49 views

回答

3

你需要安装SFTP driver为Flysystem,图书馆Laravel用于其文件系统服务:

composer require league/flysystem-sftp 

下面是一个示例配置,你可以调整。添加到disks阵列中配置/ filesystems.php

'sftp' => [ 
    'driver' => 'sftp', 
    'host' => 'example.com', 
    'port' => 21, 
    'username' => 'username', 
    'password' => 'password', 
    'privateKey' => 'path/to/or/contents/of/privatekey', 
    'root' => '/path/to/root', 
    'timeout' => 10, 
] 

扩展Laravel的文件系统与新的驱动程序通过添加以下代码的AppServiceProviderboot()方法(或其他适当的服务提供者):

use Storage; 
use League\Flysystem\Filesystem; 
use League\Flysystem\Sftp\SftpAdapter; 
... 
public function boot() 
{ 
    Storage::extend('sftp', function ($app, $config) { 
     return new Filesystem(new SftpAdapter($config)); 
    }); 
} 

然后你可以使用Laravel的API,你会为本地文件系统:

Storage::disk('sftp')->put('path/filename.txt', $fileContents); 
+0

谢谢。看起来很有希望。我安装了SFTP驱动程序并添加了配置,但收到以下错误消息:'[InvalidArgumentException] Driver [sftp]不受支持。' –

+0

我尝试了以下配置:https://github.com/thephpleague/flysystem-sftp它完美地工作。我无法使用存储外观,但对我来说没问题。 –

+0

啊,看起来我错过了一步......对此感到抱歉。更新! –