@Override
    public PathAttributes find(final Path file, final ListProgressListener listener) throws BackgroundException {
        if(file.isRoot()) {
            return PathAttributes.EMPTY;
        }
        try {
            final FileAttributes stat;
            if(file.isSymbolicLink()) {
                stat = session.sftp().lstat(file.getAbsolute());
            }
            else {
                stat = session.sftp().stat(file.getAbsolute());
            }
            switch(stat.getType()) {
                case BLOCK_SPECIAL:
                case CHAR_SPECIAL:
                case FIFO_SPECIAL:
                case SOCKET_SPECIAL:
                case REGULAR:
                case SYMLINK:
                    if(!file.getType().contains(Path.Type.file)) {
                        throw new NotfoundException(String.format("File %s is of type %s but expected %s",
                                file.getAbsolute(), stat.getType(), file.getType()));
                    }
                    break;
                case DIRECTORY:
                    if(!file.getType().contains(Path.Type.directory)) {
                        throw new NotfoundException(String.format("File %s is of type %s but expected %s",
                                file.getAbsolute(), stat.getType(), file.getType()));
                    }
                    break;
            }
            return this.toAttributes(stat);
        }
        catch(IOException e) {
            throw new SFTPExceptionMappingService().map("Failure to read attributes of {0}", e, file);
        }
    }
@Test
    public void testFindDirectory() throws Exception {
        final Path test = new Path(new SFTPHomeDirectoryService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory));
        new SFTPDirectoryFeature(session).mkdir(test, new TransferStatus());
        final SFTPAttributesFinderFeature f = new SFTPAttributesFinderFeature(session);
        final PathAttributes attributes = f.find(test);
        assertNotNull(attributes);
        // Test wrong type
        try {
            f.find(new Path(test.getAbsolute(), EnumSet.of(Path.Type.file)));
            fail();
        }
        catch(NotfoundException e) {
            // Expected
        }
    }