[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15941023#comment-15941023
 ] 

Piotr Praszmo commented on SSHD-733:
------------------------------------

I'm having similar (probably the same) issue:

{code}
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;

import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.client.subsystem.sftp.SftpClient;
import org.apache.sshd.client.subsystem.sftp.SftpClient.CloseableHandle;
import org.apache.sshd.client.subsystem.sftp.SftpClient.DirEntry;
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;

public class Main {

        private static final String USERNAME = "my username";
        private static final String PASSWORD = "my password";

        public static void main(final String[] args) throws Exception {

                Files.delete(Paths.get("my_link"));
                final Path link = 
Files.createSymbolicLink(Paths.get("my_link"), Paths.get("/")).toAbsolutePath();

                final SshServer server = SshServer.setUpDefaultServer();
                server.setHost("localhost");
                server.setPort(0);
                server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
                server.setPasswordAuthenticator(
                                (username, password, session) -> 
USERNAME.equals(username) && PASSWORD.equals(password));

                server.setSubsystemFactories(Collections.singletonList(new 
SftpSubsystemFactory()));
                server.setFileSystemFactory(new 
VirtualFileSystemFactory(Paths.get("/")));
                server.start();

                System.out.println("openssh:");
                test(22, link);

                System.out.println("mina:");
                test(server.getPort(), link);
        }

        private static void test(final int port, final Path path) throws 
IOException {
                try (final SshClient client = SshClient.setUpDefaultClient()) {
                        client.setHostConfigEntryResolver((h, p, u) -> null);
                        client.start();
                        try (ClientSession session = client.connect(USERNAME, 
"localhost", port).verify().getSession()) {
                                session.addPasswordIdentity(PASSWORD);
                                session.auth().verify();
                                final SftpClient sftp = 
session.createSftpClient();
                                try {
                                        try (CloseableHandle dir = 
sftp.openDir(path.toString())) {
                                                for (final DirEntry entry : 
sftp.listDir(dir)) {
                                                        
System.out.print(entry.getFilename() + " ");
                                                }
                                                System.out.println();
                                        }
                                } catch (final Exception e) {
                                        e.printStackTrace();
                                }
                        }
                }
        }
}
{code}

Produces following output:

{code}
openssh:
vmlinuz libx32 usr srv sbin tmp lost+found dev initrd.img.old var etc home 
media . opt initrd.img sys run proc lib root lib64 boot bin vmlinuz.old mnt 
lib32 .. 
mina:
SFTP error (SSH_FX_NOT_A_DIRECTORY): Internal NotDirectoryException: 
/tmp/workspace/test/my_link
        at 
org.apache.sshd.client.subsystem.sftp.AbstractSftpClient.throwStatusException(AbstractSftpClient.java:169)
        at 
org.apache.sshd.client.subsystem.sftp.AbstractSftpClient.checkHandleResponse(AbstractSftpClient.java:204)
        at 
org.apache.sshd.client.subsystem.sftp.AbstractSftpClient.checkHandle(AbstractSftpClient.java:184)
        at 
org.apache.sshd.client.subsystem.sftp.AbstractSftpClient.openDir(AbstractSftpClient.java:853)
        at test.Main.test(Main.java:57)
        at test.Main.main(Main.java:44)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
        at java.lang.Thread.run(Thread.java:745)
{code}

`/tmp/workspace/test/my_link` is a symlink to directory (created at the start 
of main).
On port 22 I'm running:
{code}
SSH-2.0-OpenSSH_7.4p1 Debian-6
{code}
OpenSSH lists the contents of symlinked directory while mina returns 
SSH_FX_NOT_A_DIRECTORY.
The same behavior can be observer using different client (sftp).
I'm not sure which behavior is the correct one though.


> SSHD server displays file symlinks instead of dir symlinks
> ----------------------------------------------------------
>
>                 Key: SSHD-733
>                 URL: https://issues.apache.org/jira/browse/SSHD-733
>             Project: MINA SSHD
>          Issue Type: Wish
>    Affects Versions: 1.2.0
>         Environment: Windows/Linux
>            Reporter: Marcin Kozakiewicz
>            Priority: Minor
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
>         _server.setHost("localhost");
>         _server.setPort(PORT);
>         _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
>         _server.setPasswordAuthenticator(new PasswordAuthenticator() {
>             @Override
>             public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
>                 return USERNAME.equals(username) && PASSWORD.equals(password);
>             }
>         });
>         _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
>         _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
>         _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to