fake-sftp-server-lambda icon indicating copy to clipboard operation
fake-sftp-server-lambda copied to clipboard

It gives Auth fail when try to connect via jsch

Open chanurahemal opened this issue 4 years ago • 2 comments
trafficstars

My code is as bellow. The server is creating properly and i can put files as well. But when i try to connect to server using jsch, it always gives "Auth fail" in session.connect()

    withSftpServer(server -> {
        server.addUser("username", "password1").setPort(1234);

        JSch jsch = new JSch();
        Session session = null;
        Channel channel = null;
        ChannelSftp channelSftp = null;
        final int rPort = Integer.parseInt("22");
        String knownHostPublicKey = "127.0.0.1" + " ssh-rsa " + <<HOST-KEY>>;
        jsch.setKnownHosts(new ByteArrayInputStream(knownHostPublicKey.getBytes()));
        session = jsch.getSession("username", "127.0.0.1", rPort);
        session.setPassword("password1");
        session.setTimeout(25000);
        session.connect(25000); **//Auth fail here**
        channel = session.openChannel("sftp");
        channel.connect();
        channelSftp = (ChannelSftp) channel;

    });

chanurahemal avatar Aug 05 '21 04:08 chanurahemal

The port of the Fake SFTP server is 1234 but you connect to port 22. I think you connect to an SFTP server that is running on your machine instead of Fake SFTP server and therefore the authentication fails. Can you please change the following two lines:

server.addUser("username", "password1"); // don't set the port. It is not necessary.
...
session = jsch.getSession("username", "127.0.0.1", server.getPort());
...

and tell me whether it still fails.

stefanbirkner avatar Nov 20 '21 00:11 stefanbirkner

Thank you very much for your time to look at this issue @stefanbirkner

Yeah, it was the wrong port number i was connecting. Thank you.

I have another question regarding this fake sftp server. I need to have a sftp server which supports not only password, but also with ssh keys(addIdentity). I couldn't find it in the current fake sftp server. Is it right? do you have any idea to add that facility to this server any soon?

Thank you very much again for your support

chanurahemal avatar Nov 30 '21 05:11 chanurahemal