title: Why doesn't s3fs work like a normal file system with Apache MINA SSHD?
body: <p>So I'm trying to create a Java SFTP server which acts as a front end for Apache S3 buckets.  You connect via SFTP and manage S3 files in buckets like they were files on the SFTP server.</p>
  
  <p>I've used <a href="https://mina.apache.org/sshd-project/" rel="nofollow">Apache MINA</a> (v1.2.0) as the SFTP server, which works fine using an <code>SftpSubsystemFactory</code> and default <code>FileSystemFactory</code> (providing the local filesystem).<br>
  I've chosen <a href="https://github.com/Upplication/Amazon-S3-FileSystem-NIO2" rel="nofollow">Amazon-S3-FileSystem-NIO2</a>(v1.3.0) as the <code>FileSystem</code>, which uses the <a href="https://github.com/aws/aws-sdk-java" rel="nofollow">Apache AWS SDK</a> and seems to be the best option out there</p>
  
  <pre><code>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&lt;String, Object&gt;(), classLoader);
          return s3FileSystem;
      }
  }
  </code></pre>
  
  <p>I'm just setting this as the <code>FileSystemFactory</code> for MINA</p>
  
  <pre><code>SshServer sshd = SshServer.setUpDefaultServer();
  sshd.setKeyPairProvider(buildHostKeyProviderFromFile(hostKeyType));
  sshd.setPasswordAuthenticator(createPasswordAuthenticator());
  sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
  sshd.setSubsystemFactories(createSubsystemFactories());
  sshd.setFileSystemFactory(createFileSystemFactory());
  
  URI uri = URI.create("s3:///s3.amazonaws.com/my_bucket"); 
  FileSystemFactory s3FileSystemFactory = new S3FileSystemFactory(uri);
  sshd.setFileSystemFactory(s3FileSystemFactory);
  </code></pre>
  
  <p>I can connect to this server with FileZilla/Command Line but it auto connects to the <code>ImageTransfer</code> bucket (not <code>my_bucket</code>).  I can navigate to other buckets, even sub buckets but can't display the contents, everything just looks like an empty directory.</p>
  
  <p>This can be done via the <code>FileSystem</code> <a href="https://github.com/Upplication/Amazon-S3-FileSystem-NIO2" rel="nofollow">I'm using</a> as I can list directory contents, like so </p>
  
  <pre><code>    Path p = s3FileSystem.getPath("/my_bucket");
      String contents = "";
      try (DirectoryStream&lt;Path&gt; stream = Files.newDirectoryStream(p, "*")) {
          for (Path file : stream) {
              contents += "\n \t - " + file.getFileName();
          }
      } catch (IOException | DirectoryIteratorException x) {}
  </code></pre>
  
  <p>I've been looking through the s3fs, MINA and AWS code (as the documentation is very limited) but can't pinpoint the source of this problem.  Can anyone shed any light on what I'm doing wrong?</p>
  
  <p><strong>Logging</strong></p>
  
  <p>With logging for all libraries switched on, I get only one issue I can see</p>
  
  <pre><code>"HEAD
  application/x-www-form-urlencoded; charset=utf-8
  Fri, 20 May 2016 09:58:07 GMT
  /MYURL/."
  2016-05-20 10:58:07.240 DEBUG 13323 --- [system-thread-1] c.a.http.impl.client.SdkHttpClient       : Stale connection check
  2016-05-20 10:58:07.243 DEBUG 13323 --- [system-thread-1] c.a.http.impl.client.SdkHttpClient       : Attempt 1 to execute request
  2016-05-20 10:58:07.434 DEBUG 13323 --- [system-thread-1] c.a.http.impl.client.SdkHttpClient       : Connection can be kept alive indefinitely
  2016-05-20 10:58:07.435 DEBUG 13323 --- [system-thread-1] com.amazonaws.request                    : Received error response: com.amazonaws.services.s3.model.AmazonS3Exception: Not Found (Service: null; Status Code: 404; Error Code: 404 Not Found; Request ID: MYREQID), S3 Extended Request ID: MYEXTREQID
  </code></pre>