MINA SSHD
  1. MINA SSHD
  2. SSHD-133

E command not handled for single file upload

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.6.0
    • Labels:
      None

      Description

      Using the Ganymed SSH2 client (build 210 from here http://www.ganymed.ethz.ch/ssh2/) uploading a file to an instance of Mina SSHD causes the following exception:

      java.io.IOException: Expected a C message but got 'E'
      at org.apache.sshd.server.command.ScpCommand.writeFile(ScpCommand.java:299)
      at org.apache.sshd.server.command.ScpCommand.run(ScpCommand.java:174)
      at java.lang.Thread.run(Thread.java:662)

      Further investigation into the issue reveals that the Ganymed client ends the C command sequence with an E command. Looking at the code for ScpCommand run() method I notice the following switch statement:

      switch (c)

      { case -1: return; case 'D': isDir = true; case 'C': case 'E': line = ((char) c) + readLine(); break; default: //a real ack that has been acted upon already continue; }

      The E command is part of the fall through for C and D command where the respective handlers for these commands assert that a command is either a C or D. If either of these handlers receive an E then an exception is raised.

      Changing the switch statement to prevent the E from reaching the writeFile or writeDir as follows remedies the issue for me:

      switch (c)

      { case -1: return; case 'D': isDir = true; case 'C': line = ((char) c) + readLine(); break; case 'E': readLine(); // consume remainder of line return; default: //a real ack that has been acted upon already continue; }

      I'm using a version compiled from the current SVN head revision 1132372

        Activity

        Chris Lowe created issue -
        Hide
        Chris Lowe added a comment - - edited

        Here's the essence of what I was trying to achieve with the Ganymed library:

        import ch.ethz.ssh2.Connection;
        import ch.ethz.ssh2.Session;
        // ...

        public class TestSshdFixture {

        public testScp()

        { final SshServer sshd = SshServer.setUpDefaultServer(); sshd.setCommandFactory(new ScpCommandFactory()); // ... other sshd init code omitted for brevity sshd.start(); // begin client config final Connection conn = new Connection("127.0.0.1"); conn.connect(null, 5000, 0); final SCPClient scp_client = new SCPClient(conn); // create properties file to upload final Properties props = new Properties(); props.setProperty("test", "test-passed"); final byte[] uploadBytes = toBytes(properties, ""); scp_client.put(propertyBytes, filename, path); }

        private byte[] toBytes(final Properties properties, final String comments) {
        try

        { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); properties.store(baos, comments); baos.close(); final byte[] bytes = baos.toByteArray(); return bytes; }

        catch (final IOException cause)

        { throw new RuntimeException("Failed to output properties to byte[]", cause); }

        }

        }

        Show
        Chris Lowe added a comment - - edited Here's the essence of what I was trying to achieve with the Ganymed library: import ch.ethz.ssh2.Connection; import ch.ethz.ssh2.Session; // ... public class TestSshdFixture { public testScp() { final SshServer sshd = SshServer.setUpDefaultServer(); sshd.setCommandFactory(new ScpCommandFactory()); // ... other sshd init code omitted for brevity sshd.start(); // begin client config final Connection conn = new Connection("127.0.0.1"); conn.connect(null, 5000, 0); final SCPClient scp_client = new SCPClient(conn); // create properties file to upload final Properties props = new Properties(); props.setProperty("test", "test-passed"); final byte[] uploadBytes = toBytes(properties, ""); scp_client.put(propertyBytes, filename, path); } private byte[] toBytes(final Properties properties, final String comments) { try { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); properties.store(baos, comments); baos.close(); final byte[] bytes = baos.toByteArray(); return bytes; } catch (final IOException cause) { throw new RuntimeException("Failed to output properties to byte[]", cause); } } }
        Guillaume Nodet made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Guillaume Nodet [ gnt ]
        Fix Version/s 0.6.0 [ 12315514 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Guillaume Nodet
            Reporter:
            Chris Lowe
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development