flysystem icon indicating copy to clipboard operation
flysystem copied to clipboard

Missing getConnection method on v3 SftpAdapter

Open ragingdave opened this issue 3 years ago • 2 comments

Bug Report

Q A
BC Break yes
Version 3

Summary

In upgrading an application, we switched from v2 to v3 of the sftp adapter, with this change code that was calling directly to the connection (for performance reasons) is no longer working with the error that getConnection is now an undefined method.

Storage::disk('sftp')->getAdapter()->getConnection()->exec('ls /path/to/lots/of/files | grep something-to-limit | sort')

The issue here is that with a very (very) large number of files, php runs out memory when attempting to list the files even when attempting to use the new filter chain method on files call like:

Storage::disk('sftp')->files('/path/to/lots/of/files')->filter(fn ($atts) => str_contains($atts->path(), 'filter-to'))

I can't exactly find where the getConnection was removed at this point, but there needs to be some way to get direct access for situations like this again

ragingdave avatar Aug 04 '22 15:08 ragingdave

Hi, these operations should be done without using Flysystem, it does not match the purpose of the library. You can use the connection provider mechanisms to get the connection if you feel like it, but the getConnection will not be returned to the interface.

frankdejonge avatar Aug 04 '22 16:08 frankdejonge

So I guess the reason I would see this as a breaking change, but also IMHO an unnecessary breaking change, is that now, in order to connect to a filesystem such as sftp, and run an arbitrary command, we would now have to yes build up a whole new connection provider, when the connection provider is already present and configured in flysystem. While direct access might not be the purpose of flysystem, it was the de-duplication of the same configuration that enabled such simple direct access. So perhaps instead of getting the connection directly, would something like accessors on the connection provider be something that would be given? I mean at the end of the day, it's basically the same interaction but it makes it so there doesn't have to be any manual work to get a connection provider that has already been created anyways.

ragingdave avatar Aug 08 '22 19:08 ragingdave

Flysystem is not a service provider and crating another object is not a problem. You can literally do it. Flysystem is not a library for arbitrary Sftp commands, that's what PHPSeclib is for.

frankdejonge avatar Aug 14 '22 20:08 frankdejonge