2017-09-26 52 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

啊,看起來我錯過了一步......對此感到抱歉。更新! –