Skip to content

SCP upload to Windows 11 Open SSH fails with no such file or directory error #929

@robertpatrick

Description

@robertpatrick

We are using SSHJ to add remoting capabilities to our app. We are currently testing cross-platform capabilities where the client is running on Linux connecting to a Windows 11 Enterprise server using the OpenSSH server provided by the Windows distribution. SSH is working fine. SCP download is working fine. SCP upload is failing with:

Exception in thread "main" net.schmizz.sshj.xfer.scp.SCPRemoteException: Remote SCP command had error: scp: 'c:\Temp\model.yaml': No such file or directory
        at net.schmizz.sshj.xfer.scp.SCPEngine.check(SCPEngine.java:73)
        at net.schmizz.sshj.xfer.scp.SCPEngine.sendMessage(SCPEngine.java:133)
        at net.schmizz.sshj.xfer.scp.SCPUploadClient.sendFile(SCPUploadClient.java:105)
        at net.schmizz.sshj.xfer.scp.SCPUploadClient.process(SCPUploadClient.java:84)
        at net.schmizz.sshj.xfer.scp.SCPUploadClient.startCopy(SCPUploadClient.java:76)
        at net.schmizz.sshj.xfer.scp.SCPUploadClient.copy(SCPUploadClient.java:54)
        at net.schmizz.sshj.xfer.scp.SCPUploadClient.copy(SCPUploadClient.java:47)
        at net.schmizz.sshj.xfer.scp.SCPUploadClient.copy(SCPUploadClient.java:43)
        at net.schmizz.sshj.xfer.scp.SCPFileTransfer.upload(SCPFileTransfer.java:98)
        at net.schmizz.sshj.xfer.scp.SCPFileTransfer.upload(SCPFileTransfer.java:61)
        at net.schmizz.sshj.xfer.scp.SCPFileTransfer.upload(SCPFileTransfer.java:55)
        at com.oracle.test.SSHTest.main(SSHTest.java:36)

The odd thing is that scp from the command-line works fine.

[rpatrick@rpatrick-1 ssh-test]$ scp ./model.yaml rpatrick@<internal-hostname-redacted>:c:\\Temp\\model.yaml
model.yaml                                                                                                                                                                                100%  486   238.1KB/s   00:00
[rpatrick@rpatrick-1 ssh-test]$

My code is just a little sample that I created trying to debug this problem. As you can see, it isn't doing anything fancy and is allowing SSHJ to get the default username and SSH private key (from ~/.ssh/id_rsa).

package com.oracle.test;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;
import net.schmizz.sshj.xfer.scp.SCPFileTransfer;


public class SSHTest {
    public static void main(String[] args) throws Exception {
        try (SSHClient sshClient = new SSHClient()) {
            sshClient.loadKnownHosts();
            sshClient.connect("<internal-hostname-redacted>");
            Session session = null;
            try {
                sshClient.authPublickey(System.getProperty("user.name"));
                session = sshClient.startSession();
                final Command cmd = session.exec("wmic os get caption");
                System.out.print(IOUtils.readFully(cmd.getInputStream()));
                cmd.join(5, TimeUnit.SECONDS);
                System.out.println("\n** exit status: " + cmd.getExitStatus() + "\n\n");

                SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer();
                scpFileTransfer.download("c:\\Temp\\ssh\\model.yaml", "./model.yaml");
                System.out.println("Downloaded file\n\n");

                scpFileTransfer = sshClient.newSCPFileTransfer();
                scpFileTransfer.upload("./model.yaml", "c:\\Temp\\model.yaml");
                System.out.println("Uploaded file\n\n");
            } finally {
                if (session != null) {
                    try { session.close(); } catch (IOException ex) { /* ignore */ }
                }
                sshClient.disconnect();
            }
        }
    }
}

In the output from this program, I see the following before the stack trace:

Caption
Microsoft Windows 11 Enterprise


** exit status: 0


Downloaded file


Exception in thread "main" net.schmizz.sshj.xfer.scp.SCPRemoteException: Remote SCP command had error: scp: 'c:\Temp\model.yaml': No such file or directory
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions