hellsAngel23 / ganymed-ssh-2

Automatically exported from code.google.com/p/ganymed-ssh-2
Other
0 stars 0 forks source link

scp quoting breaks some servers #52

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use ganymed SCPClient to copy a file from a Cisco IOS router
2. Note that it doesn't work, saying 'file not found', and that the error has 
quotes around the file name
3. Note that it does work with the attached patch

SSH Server version: Cisco IOS Software, CSR1000V Software 
(X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 15.4(2)S, RELEASE SOFTWARE (fc2)
Ganymed release: trunk
Client platform: Mac OS-X

I've been trying to use the ganymed ssh client against Cisco devices
(you can scp in/out their config), and after much playing about I've
found that the Cisco device will not accept the filenames being
quoted internally to ssh by use of double quotes.

The ganymed client quotes the remote filename so that it forms a
single parameter for the remote (server side) scp process. Cisco
won't accept this. openssh's scp does not quote the name passed
with quote marks; I think it's escaping spaces are similar.

As a fix, I've provided an overridable "quote" method which uses
your existing quote method. This allows a derived class to override
it. For instance, I have:

public class CiscoSCPClient extends SCPClient {

    public CiscoSCPClient(Connection conn) {
        super(conn);
    }

    public String quote(final String filename)
    {
        return filename.replaceAll(" ", "\\ ");
    }
}

I've also provided a public getter method for the Connection, as this
allows you to override the get() and put() methods satisfactorily
should more control be needed.

Hope that's useful.

PLEASE post a self-contained short java example.

    public static void main(String[] args) throws Exception {
        Connection sshConn = new Connection("your.ip.address.here");
        try {
            sshConn.connect();
        } catch (Exception e) {
            throw new IOException("Could not connect to server");
        } finally {

        }

        boolean isAuthenticated = sshConn.authenticateWithPassword("username", "password");

        if (!isAuthenticated) {
            throw new IOException("Could not authenticate to server");
        }

        SCPClient scpClient = new SCPClient(sshConn);

        InputStream is = scpClient.get("startup-config");
        byte[] bytes = IOUtils.readFully(is, -1, true);
        is.close();

        String conf = new String(bytes);
        System.out.println (conf);

        sshConn.close();        
    }

Cisco sshd cannot be started in debug mode like sshd therefore no debug is 
provided.

Original issue reported on code.google.com by alex.bl...@gmail.com on 26 Nov 2014 at 12:43

Attachments: