You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2011/07/01 14:37:50 UTC

svn commit: r1141917 - in /mina/sshd/trunk/sshd-core: pom.xml src/main/java/org/apache/sshd/server/command/ScpCommand.java src/test/java/org/apache/sshd/ScpTest.java

Author: gnodet
Date: Fri Jul  1 12:37:49 2011
New Revision: 1141917

URL: http://svn.apache.org/viewvc?rev=1141917&view=rev
Log:
[SSHD-133] E command not handled for single file upload

Modified:
    mina/sshd/trunk/sshd-core/pom.xml
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java
    mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/ScpTest.java

Modified: mina/sshd/trunk/sshd-core/pom.xml
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/pom.xml?rev=1141917&r1=1141916&r2=1141917&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/pom.xml (original)
+++ mina/sshd/trunk/sshd-core/pom.xml Fri Jul  1 12:37:49 2011
@@ -93,6 +93,12 @@
             <artifactId>commons-httpclient</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>ch.ethz.ganymed</groupId>
+            <artifactId>ganymed-ssh2</artifactId>
+            <version>build210</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java?rev=1141917&r1=1141916&r2=1141917&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java Fri Jul  1 12:37:49 2011
@@ -20,18 +20,13 @@ package org.apache.sshd.server.command;
 
 import java.io.ByteArrayOutputStream;
 import java.io.EOFException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Arrays;
 
 import org.apache.sshd.common.util.DirectoryScanner;
-import org.apache.sshd.common.util.SelectorUtils;
 import org.apache.sshd.server.Command;
-import org.apache.sshd.server.CommandFactory;
 import org.apache.sshd.server.Environment;
 import org.apache.sshd.server.ExitCallback;
 import org.apache.sshd.server.FileSystemAware;
@@ -157,9 +152,11 @@ public class ScpCommand implements Comma
                         case 'D':
                             isDir = true;
                         case 'C':
-                        case 'E':
                             line = ((char) c) + readLine();
                             break;
+                        case 'E':
+                            readLine();
+                            return;
                         default:
                             //a real ack that has been acted upon already
                             continue;

Modified: mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/ScpTest.java?rev=1141917&r1=1141916&r2=1141917&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/ScpTest.java (original)
+++ mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/ScpTest.java Fri Jul  1 12:37:49 2011
@@ -18,28 +18,33 @@
  */
 package org.apache.sshd;
 
-import java.net.ServerSocket;
-import java.io.OutputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.InputStream;
 import java.io.IOException;
-import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.ServerSocket;
+import java.util.Properties;
 
-import org.junit.Before;
-import org.junit.After;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
-import org.apache.sshd.util.EchoShellFactory;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
-import org.apache.sshd.server.command.ScpCommandFactory;
+import ch.ethz.ssh2.Connection;
+import ch.ethz.ssh2.SCPClient;
+import com.jcraft.jsch.ChannelExec;
 import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
 import com.jcraft.jsch.Logger;
 import com.jcraft.jsch.UserInfo;
-import com.jcraft.jsch.Channel;
-import com.jcraft.jsch.ChannelExec;
+import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
+import org.apache.sshd.server.command.ScpCommandFactory;
+import org.apache.sshd.util.BogusPasswordAuthenticator;
+import org.apache.sshd.util.EchoShellFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 /**
  * Test for SCP support.
@@ -65,7 +70,9 @@ public class ScpTest {
         sshd.setShellFactory(new EchoShellFactory());
         sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
         sshd.start();
+    }
 
+    protected com.jcraft.jsch.Session getJschSession() throws JSchException {
         JSch sch = new JSch();
         sch.setLogger(new Logger() {
             public boolean isEnabled(int i) {
@@ -97,11 +104,14 @@ public class ScpTest {
             }
         });
         session.connect();
+        return session;
     }
 
     @After
     public void tearDown() throws Exception {
-        session.disconnect();
+        if (session != null) {
+            session.disconnect();
+        }
         sshd.stop();
     }
 
@@ -114,6 +124,8 @@ public class ScpTest {
 
     @Test
     public void testScp() throws Exception {
+        session = getJschSession();
+
         String data = "0123456789\n";
 
         File root = new File("target/scp");
@@ -146,6 +158,30 @@ public class ScpTest {
         assertFileLength(target, data.length(), 5000);
     }
 
+    @Test
+    public void testWithGanymede() throws Exception {
+        // begin client config
+        final Connection conn = new Connection("localhost", port);
+        conn.connect(null, 5000, 0);
+        conn.authenticateWithPassword("sshd", "sshd");
+        final SCPClient scp_client = new SCPClient(conn);
+        final Properties props = new Properties();
+        props.setProperty("test", "test-passed");
+        scp_client.put(toBytes(props, ""), "test.properties", "target/scp/gan");
+        scp_client.put(toBytes(props, ""), "test2.properties", "target/scp/gan");
+    }
+
+    private byte[] toBytes(final Properties properties, final String comments) {
+        try {
+            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            properties.store(baos, comments);
+            baos.close();
+            return baos.toByteArray();
+        } catch (final IOException cause) {
+            throw new RuntimeException("Failed to output properties to byte[]", cause);
+        }
+    }
+
     protected void assertFileLength(File file, long length, long timeout) throws Exception{
         boolean ok = false;
         while (timeout > 0) {
@@ -269,7 +305,7 @@ public class ScpTest {
         os.write(("D0755 0 " + dirName + "\n").getBytes());
         os.flush();
         assertEquals(0, is.read());
-        os.write(("C7777 "+ data.length() + " " + fileName + "\n").getBytes());
+        os.write(("C7777 " + data.length() + " " + fileName + "\n").getBytes());
         os.flush();
         assertEquals(0, is.read());
         os.write(data.getBytes());