Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell expansion does not work #212

Closed
juddgaddie opened this issue Sep 7, 2015 · 11 comments
Closed

Shell expansion does not work #212

juddgaddie opened this issue Sep 7, 2015 · 11 comments

Comments

@juddgaddie
Copy link
Contributor

It seems as though shell expansion is not supported is this correct or am I doing something wrong.

The example below will not find the file test_file
unless you explicitly specify "test_file"

  SSHClient ssh = new SSHClient();
        // ssh.useCompression(); // Can lead to significant speedup (needs JZlib in classpath)
        ssh.loadKnownHosts();
        ssh.connect("localhost");
        try {
            ssh.authPublickey(System.getProperty("user.name"));
            ssh.newSCPFileTransfer().download("*_file", new FileSystemFile("/tmp/"));
        } finally {
            ssh.disconnect();
        }

Thanks

@juddgaddie
Copy link
Contributor Author

The stack trace is:

Exception in thread "main" net.schmizz.sshj.xfer.scp.SCPException: Remote SCP command returned error: scp: *_file: No such file or directory
at net.schmizz.sshj.xfer.scp.SCPDownloadClient.process(SCPDownloadClient.java:126)
at net.schmizz.sshj.xfer.scp.SCPDownloadClient.startCopy(SCPDownloadClient.java:79)
at net.schmizz.sshj.xfer.scp.SCPDownloadClient.copy(SCPDownloadClient.java:50)
at net.schmizz.sshj.xfer.scp.SCPFileTransfer.download(SCPFileTransfer.java:69)
at net.schmizz.sshj.SCPDownload.main(SCPDownload.java:36)
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:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

@juddgaddie
Copy link
Contributor Author

I have found this is caused by SCPEngine.java quoting the source path:

SCPEngine.java line 112:
cmd.append("'").append(path.replaceAll("'", "'")).append("'");

Why the requirement to quote, could we optionally not quote ?

@juddgaddie
Copy link
Contributor Author

linked to #184

@hierynomus
Copy link
Owner

Have you verified it works without quoting?

@juddgaddie
Copy link
Contributor Author

Yes

@hierynomus
Copy link
Owner

OK, what do you suggest as a good approach then? As said in #184 not quoting is not a good idea. Double quotes could work I think, but do they work always?

@juddgaddie
Copy link
Contributor Author

Double quotes does not solve the issue. If you want to escape space char then \ works, on Linux at least. I am not sure if a universal escaping solution exists across operating system, file systems and ssh servers. Leaving escaping to the user or at least a way of opting out of escaping is required for sshj to at least be functional without a universal escaping mechanism.

I am currently using jsch and unfortunately can't move to sshj until this is resolved.

@juddgaddie
Copy link
Contributor Author

Could we start compiling a list of all the characters that need to be escaped, across platforms and see if there is a common set?

In the mean time can we leave escaping to the user, or at least make it optional by providing a Typed interface, eg. RemoteFile which will be escaped and String remoteFile which leaves it up to the user?

@juddgaddie
Copy link
Contributor Author

Thanks for this patch, I'll test it out.

@hierynomus
Copy link
Owner

Let me know. It seems that actually Apache Mina does not need any escaping. I have not had the time to test it out on OpenSSH and others. If you could let me know the results of your tests?

@juddgaddie
Copy link
Contributor Author

It's working for our use cases with openssh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants