talvbansal/laravel-public-sftp

An extension to the flysystem Sftp adapter that allows you to configure a public URL for files to be accessible from.

dev-master 2017-05-02 14:08 UTC

This package is auto-updated.

Last update: 2024-12-20 08:10:27 UTC


README

An extension to the sftp flysystem adapter that allows you to configure a public URL for files to be accessible from.

build status Total Downloads coverage report License

Introduction

The default sftp flysystem adapter does not have a method to get the URL of files on the disk, instead a if you try and call the url() method on the disk instance a RuntimeException will be thrown.

I wrote this extension to the sftp adapter so that i could upload files using my media-manager package and store the files on a remote server yet still have them in a publicly accessible place.

Installation

To get started, install public sftp adapter via the Composer package manager:

composer require talvbansal/laravel-public-sftp

Register the adapter in the providers array of your config/app.php configuration file:

\TalvBansal\SftpPublic\Providers\SftpPublicServiceProvider::class,

After this a new disk will be automatically registered called public-sftp.

Configuration

Add the relevant configuration from the keys below to access your ssh enabled server:

SFTP_HOST=myserver.com
SFTP_USERNAME=username
SFTP_PW=password
SFTP_PRIVATE_KEY=/optional/path/to/private/key
SFTP_ROOT=/path/to/storage/folder
SFTP_PUBLIC_ROOT=https://public-url/to-folder-above

The new value to pay attention to here is SFTP_PUBLIC_ROOT which should be a publicly accessible URL that is serving the contents of the SFTP_ROOT folder.

So if you were using nginx or apache to serve the /var/www/public folder on a server over https on a domain of example.com the values would look like this:

SFTP_ROOT=/var/www/public
SFTP_PUBLIC_ROOT=https://example.com

You can now use the public-sftp disk as a filesystem within laravel and will be able to call the url() method on the disk instance to get a publicly accessible URL of an uploaded file.

Credits

License

The MIT License (MIT). Please see License File for more information.