Hi Will,

We have developed SFTP access for our CMS on Apache Jackrabbit and
basically encountered the same 'struggle' you are facing. We actually ended
up implementing a great deal of the java.nio.FileSystem related interfaces.
Besides the interfaces you mentioned (FileSystem, FileSystemFactory, Path),
we also provide our own DirectoryStream, FileStore, FileAttributes,
FileAttributeView and FileChannel (for uploading).
I don't know how you managed file transfers, but a FileChannel is a
SeekableByteChannel, which is only implemented by RandomAccessFile. Apache
Jackrabbit is a database-driven filesystem which does not support
SeekableByteChannels, so we ended up downloading a file to a local temp
file and then using RandomAccessFile.toChannel to get a FileChannel for
downloading content.
A lot of methods on the mentioned interfaces are not implemented in our
code, because they are not being called by MINA. It also depends on the
SFTP clients you want to support.

I don't know how sophisticated the authentication has to be, and how
heavily the connection will be used in your project, but maybe an
alternative could be to mount the remote filesystem using FTP (using
CurlFtpFS for example) and use the default local filesystem implementation
from MINA.

Good luck,
Dennis

On Thu, 7 Dec 2023 at 21:01, Soderberg, Will <
will.soderb...@gehealthcare.com> wrote:

> Hello,
>
> Haven't had much luck finding answers on stackoverflow etc so trying here.
>
> I'm working on a project which uses both Apache MINA and Apache
> commons-net FTPClient to create a protocol adapter that provides an SFTP
> wrapper to access FTP servers (which cannot be upgraded to SFTP for complex
> reasons).
>
> I've been able to get authentication and file transfer working by
> hardcoding the paths, but what I'm struggling with is file+folder listing.
> FTPClient has a very simple API for this, but MINA seems to require an
> extremely sophisticated implementation of java.nio.file.FileSystem,
> FileSystemFactory, Path, etc to make this work.  I was hoping that
> implementing SftpFileSystemAccessor.openDirectory would be enough, but when
> setting breakpoints I'm not seeing that method be called in the way I would
> expect for it to be the solution.
>
> Am I overthinking this?  Which approach is correct for what I'm looking to
> do?  I can't provide a very complete implementation of FileSystem due to
> the limitations of FTP, but it seems like MINA only really uses a few
> methods from it anyway.
>
>
> Thank you
> Will
>


-- 
D.G. van der Laan, MSc
Sr. Software Engineer, team Content Management System & Online Development
Center for Information Technology
+31 (0)50 363 9273

Reply via email to