fsegers
fsegers

Reputation: 1

Using Apache Mina sshd to upload files via ScpClient fails with exception in ScpHelper.readAck()

I'm trying Apache Mina for the first time and run into the exact same error. Using the suggested upload method parameters from How to upload/download files using apache SSHD ScpClient, it still throw an exception.

My code is like this:

        try (SshClient sshClient = SshClient.setUpDefaultClient()) {
            sshClient.start();

            try (ClientSession session = sshClient.connect(sshUserName, sshHost, 22)
                                                  .verify()
                                                  .getSession()) {

                session.addPublicKeyIdentity(readKeyPair(sshPrivateKeyFile));
                AuthFuture auth = session.auth().verify();
                System.out.println("Authenticated: " + auth.isSuccess());

                ScpClientCreator scpClientCreator = ScpClientCreator.instance();
                ScpClient scpClient = scpClientCreator.createScpClient(session);

                System.out.println("Uploading...");
                Path source = Paths.get("/tmp/test.txt");
                scpClient.upload(
                        source,
                        "/home/renderingacc/README.md",
                        ScpClient.Option.Recursive,
                        ScpClient.Option.PreserveAttributes);
            } catch (Exception e) {
                throw e;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

The SSH authentication is succesful. I even tried executing a remote command, which was also successful. When the scpClient.upload() method is called, the following exception occurs:

java.io.EOFException: readAck - EOF before ACK
    at org.apache.sshd.scp.common.helpers.ScpAckInfo.readAck(ScpAckInfo.java:97)
    at org.apache.sshd.scp.common.ScpHelper.readAck(ScpHelper.java:750)
    at org.apache.sshd.scp.common.ScpHelper.sendPaths(ScpHelper.java:467)
    at org.apache.sshd.scp.client.AbstractScpClient.lambda$upload$1(AbstractScpClient.java:153)
    at org.apache.sshd.scp.client.DefaultScpClient.runUpload(DefaultScpClient.java:149)
    at org.apache.sshd.scp.client.AbstractScpClient.upload(AbstractScpClient.java:153)
    at org.apache.sshd.scp.client.ScpClient.upload(ScpClient.java:115)
    at org.apache.sshd.scp.client.ScpClient.upload(ScpClient.java:111)
    at com.philips.cmw.serializer.p4s.executor.ScpTest.run(ScpTest.java:49)
    at com.philips.cmw.serializer.p4s.executor.ScpTest.main(ScpTest.java:20)

In the source code I see it tries to read something from the SSH channel. But I have no clue why that doesn't work. Using command line scp to upload the same file to the same server with the same SSH key, works.

I hope someone can shed some light on this.

Thanks in advance.

Upvotes: 0

Views: 373

Answers (0)

Related Questions