pkg / sftp

SFTP support for the go.crypto/ssh package
BSD 2-Clause "Simplified" License
1.5k stars 379 forks source link

Interface support for sftp.NewRequestServer? #534

Closed tobychui closed 1 year ago

tobychui commented 1 year ago

Hi there, I think I might need some help on working with the NewRequestServer function.

I am trying to use sftp module in my project to serve a customized file system interface. I notice the sftp.NewRequestServer takes in a sftp.Handlers as the second parameter but there is only one implementation (InMemHandler) that matches the Handler type.

Is there another request server function that I can use by passing in an interface that implement the same functions as sftp.Handler? Or if there are any way for me to create a sftp.Handlers struct object by passing in file system abstractions in existing sftp package?

Thanks in advance!

drakkan commented 1 year ago

Hi, you have to implement the 4 request handlers here then you pass it to sftp.NewRequestServer

tobychui commented 1 year ago

Hi @drakkan,

Thanks. I didn't notice the 4 request handlers themselves are interface. I just implemented the matching functions for the 4 handlers and everything is working now!

For those who are also confused by the example, you can simply copy the InMemHandler into a new go file and change the contents of the exported functions for implementing your own sftp.Handlers object. Many of the unexported fields are for handling mutex / lock mechanism. Those are not straightly necessary if your file system abstraction already handle concurrent read write by itself.