You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Chris Lowe (JIRA)" <ji...@apache.org> on 2011/06/05 13:34:47 UTC

[jira] [Issue Comment Edited] (SSHD-133) E command not handled for single file upload

    [ https://issues.apache.org/jira/browse/SSHD-133?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13044503#comment-13044503 ] 

Chris Lowe edited comment on SSHD-133 at 6/5/11 11:32 AM:
----------------------------------------------------------

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);
		}
	}

}

      was (Author: lowecg):
    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 ThunderingHerdException("Failed to output properties to byte[]", cause);
		}
	}

}
  
> E command not handled for single file upload
> --------------------------------------------
>
>                 Key: SSHD-133
>                 URL: https://issues.apache.org/jira/browse/SSHD-133
>             Project: MINA SSHD
>          Issue Type: Bug
>            Reporter: Chris Lowe
>
> 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

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira