Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么';s3fs的工作方式与使用ApacheMina SSHD的普通文件系统类似吗?_Java_Amazon S3_Sftp_Mina_Sshd - Fatal编程技术网

Java 为什么';s3fs的工作方式与使用ApacheMina SSHD的普通文件系统类似吗?

Java 为什么';s3fs的工作方式与使用ApacheMina SSHD的普通文件系统类似吗?,java,amazon-s3,sftp,mina,sshd,Java,Amazon S3,Sftp,Mina,Sshd,因此,我试图创建一个JavaSFTP服务器,作为ApacheS3存储桶的前端。您可以通过SFTP进行连接,并管理存储桶中的S3文件,就像它们是SFTP服务器上的文件一样 我使用(v1.2.0)作为SFTP服务器,它使用sftpusystemfactory和默认FileSystemFactory(提供本地文件系统)运行良好。 我选择(v1.3.0)作为文件系统,它使用和似乎是最好的选择 public class S3FileSystemFactory implements FileSystemFa

因此,我试图创建一个JavaSFTP服务器,作为ApacheS3存储桶的前端。您可以通过SFTP进行连接,并管理存储桶中的S3文件,就像它们是SFTP服务器上的文件一样

我使用(v1.2.0)作为SFTP服务器,它使用
sftpusystemfactory
和默认
FileSystemFactory
(提供本地文件系统)运行良好。
我选择(v1.3.0)作为
文件系统
,它使用和似乎是最好的选择

public class S3FileSystemFactory implements FileSystemFactory {
    private URI uri = URI.create("localhost");

    public S3FileSystemFactory(URI uri){
        this.uri = uri;
    }

    public FileSystem createFileSystem(Session session) throws IOException {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        FileSystem s3FileSystem = FileSystems.newFileSystem(uri, new HashMap<String, Object>(), classLoader);
        return s3FileSystem;
    }
}
我可以使用FileZilla/命令行连接到此服务器,但它会自动连接到
ImageTransfer
bucket(而不是
my_bucket
)。我可以导航到其他bucket,甚至子bucket,但无法显示内容,所有内容看起来就像一个空目录

这可以通过
文件系统
完成,因为我可以列出目录内容,如下所示

    Path p = s3FileSystem.getPath("/my_bucket");
    String contents = "";
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(p, "*")) {
        for (Path file : stream) {
            contents += "\n \t - " + file.getFileName();
        }
    } catch (IOException | DirectoryIteratorException x) {}

这个问题有两个方面

首先,ApacheMina SSHD对于它使用的任何
文件系统
,都应该有
权限
属性,这很奇怪,因为这是一个特定于POSIX的属性,所以显然没有提供它

其次,apacheminasshd在get的
FileChannel

public FileChannel newFileChannel(Path path,
                                  Set<? extends OpenOption> options,
                                  FileAttribute<?>... attrs)
public FileChannel newFileChannel(路径,
设置…属性)
一个黑客解决方案就是将POSIX读/写权限硬编码到返回的S3属性中,并创建一个
S3FileChannel
,它只调用现有的方法。
这是目前我能想到的最好的解决方案。

我们对缺少的东西进行了改进,实现了S3文件系统与ApacheMina SFTP一起工作

您可以找到repo并使用maven在本地构建它

我们在MINA中使用它的方式如下:

public FileSystemFactory createFileSystemFactory(String bucketName) throws IOException, URISyntaxException {
    FileSystem fileSystem = FileSystems.newFileSystem(new URI("s3:///"), env, Thread.currentThread().getContextClassLoader());
    String bucketPath = fileSystem.getPath("/" + bucketName);

    return new VirtualFileSystemFactory(bucketPath);
}

我碰到了你的叉子。你对此有问题跟踪吗?它在什么许可下(在一些地方,它说它在麻省理工学院,在其他地方——APHE 2.0。添加
license.md
文件并澄清可能是个好主意。该项目仍在积极开发中吗?
public FileChannel newFileChannel(Path path,
                                  Set<? extends OpenOption> options,
                                  FileAttribute<?>... attrs)
public FileSystemFactory createFileSystemFactory(String bucketName) throws IOException, URISyntaxException {
    FileSystem fileSystem = FileSystems.newFileSystem(new URI("s3:///"), env, Thread.currentThread().getContextClassLoader());
    String bucketPath = fileSystem.getPath("/" + bucketName);

    return new VirtualFileSystemFactory(bucketPath);
}