diff --git a/basic/ftp/pom.xml b/basic/ftp/pom.xml
index 354d3d15..4e0d715a 100644
--- a/basic/ftp/pom.xml
+++ b/basic/ftp/pom.xml
@@ -6,7 +6,7 @@
FTP Demo
jar
- 2.0.5.RELEASE
+ 2.1.0.M1
1.2.16
4.7
@@ -60,4 +60,4 @@
http://maven.springframework.org/snapshot
-
\ No newline at end of file
+
diff --git a/basic/ftp/readme.txt b/basic/ftp/readme.txt
index 5c18cf70..6032f017 100644
--- a/basic/ftp/readme.txt
+++ b/basic/ftp/readme.txt
@@ -24,3 +24,12 @@ The output should look like this:
=====
Successfully transfered 'readme.txt' file to a remote location under the name 'readme.txt'
=====
+
+
+#### OUTBOUND GATEWAY ####
+
+Run the FtpOutoundGateway sample as a JUnit test; it creates 2 files, retrieves and removes them over ftp. It cleans up
+by removing the retrieved files. Test assumes full access to the filesystem via /tmp where the test files are created.
+Requires an ftp server running on localhost.
+
+Requires setting of user and password properties in user.properties.
\ No newline at end of file
diff --git a/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/FtpOutboundGatewaySample.java b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/FtpOutboundGatewaySample.java
new file mode 100644
index 00000000..0471a1f0
--- /dev/null
+++ b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/FtpOutboundGatewaySample.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2002-2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.samples.ftp;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.List;
+import java.util.Random;
+
+import org.junit.Test;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Demonstrates use of the outbound gateway to use ls, get and rm.
+ * Creates a temporary directory with 2 files; retrieves and removes them.
+ * @author Gary Russell
+ * @since 2.1
+ *
+ */
+public class FtpOutboundGatewaySample {
+
+ @Test
+ public void testLsGetRm() throws Exception {
+ ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
+ "classpath:/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml");
+ ToFtpFlowGateway toFtpFlow = ctx.getBean(ToFtpFlowGateway.class);
+ try {
+ String tmpDir = System.getProperty("java.io.tmpdir");
+
+ // remove the previous output files if necessary
+ new File(new File(tmpDir), "1.ftptest").delete();
+ new File(new File(tmpDir), "2.ftptest").delete();
+
+ // create a couple of files in a temp dir
+ File dir = new File(tmpDir + "/" + new Random().nextInt());
+ dir.mkdir();
+ File f1 = new File(dir, "1.ftptest");
+ f1.createNewFile();
+ File f2 = new File(dir, "2.ftptest");
+ f2.createNewFile();
+
+
+ // execute the flow (ls, get, rm, aggregate results)
+ List rmResults = toFtpFlow.lsGetAndRmFiles(dir.getAbsolutePath());
+
+
+ //Check everything went as expected, and clean up
+ assertEquals(2, rmResults.size());
+ for (Boolean result : rmResults) {
+ assertTrue(result);
+ }
+ assertTrue("Expected remote dir to be empty", dir.delete());
+ assertTrue("Could note delete retrieved file", new File(new File(tmpDir), "1.ftptest").delete());
+ assertTrue("Could note delete retrieved file", new File(new File(tmpDir), "2.ftptest").delete());
+ } finally {
+ ctx.close();
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/ToFtpFlowGateway.java b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/ToFtpFlowGateway.java
new file mode 100644
index 00000000..2fa7f23d
--- /dev/null
+++ b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/ToFtpFlowGateway.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2002-2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.samples.ftp;
+
+import java.util.List;
+
+/**
+ * @author Gary Russell
+ * @since 2.1
+ *
+ */
+public interface ToFtpFlowGateway {
+
+ public List lsGetAndRmFiles(String dir);
+}
diff --git a/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml
new file mode 100644
index 00000000..4fa6b697
--- /dev/null
+++ b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/basic/sftp/pom.xml b/basic/sftp/pom.xml
index b181b351..86f05b59 100644
--- a/basic/sftp/pom.xml
+++ b/basic/sftp/pom.xml
@@ -7,7 +7,7 @@
SFTP Demo
jar
- 2.0.5.RELEASE
+ 2.1.0.M1
1.2.16
4.7
@@ -61,4 +61,4 @@
http://maven.springframework.org/snapshot
-
\ No newline at end of file
+
diff --git a/basic/sftp/readme.txt b/basic/sftp/readme.txt
index d94508f2..565f35a3 100644
--- a/basic/sftp/readme.txt
+++ b/basic/sftp/readme.txt
@@ -33,6 +33,17 @@ Successfully transfered 'readme.txt' file to a remote location under the name 'r
NOTE: You can see that we are using SpEL via 'remote-filename-generator-expression' attribute to define the remote file name by
simply appending '_foo' to the original file name.
+
+
+#### OUTBOUND GATEWAY ####
+
+Run the FtpOutoundGateway sample as a JUnit test; it creates 2 files, retrieves and removes them over ftp. It cleans up
+by removing the retrieved files. Test assumes full access to the filesystem via /tmp where the test files are created.
+Requires sshd to be running on localhost.
+
+This sample uses a property 'private.keyfile' to point to the location of your private key.
+
+Requires setting of user, private.keyfile and, optionally, passphrase in user.properties.
====== HOW TO GENERATE KEYS ======
diff --git a/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/SftpOutboundGatewaySample.java b/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/SftpOutboundGatewaySample.java
new file mode 100644
index 00000000..9745c8be
--- /dev/null
+++ b/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/SftpOutboundGatewaySample.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2002-2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.samples.sftp;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.List;
+import java.util.Random;
+
+import org.junit.Test;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Demonstrates use of the outbound gateway to use ls, get and rm.
+ * Creates a temporary directory with 2 files; retrieves and removes them.
+ * @author Gary Russell
+ * @since 2.1
+ *
+ */
+public class SftpOutboundGatewaySample {
+
+ @Test
+ public void testLsGetRm() throws Exception {
+ ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
+ "classpath:/META-INF/spring/integration/SftpOutboundGatewaySample-context.xml");
+ ToSftpFlowGateway toFtpFlow = ctx.getBean(ToSftpFlowGateway.class);
+ try {
+ String tmpDir = System.getProperty("java.io.tmpdir");
+
+ // remove the previous output files if necessary
+ new File(new File(tmpDir), "1.ftptest").delete();
+ new File(new File(tmpDir), "2.ftptest").delete();
+
+ // create a couple of files in a temp dir
+ File dir = new File(tmpDir + "/" + new Random().nextInt());
+ dir.mkdir();
+ File f1 = new File(dir, "1.ftptest");
+ f1.createNewFile();
+ File f2 = new File(dir, "2.ftptest");
+ f2.createNewFile();
+
+
+ // execute the flow (ls, get, rm, aggregate results)
+ List rmResults = toFtpFlow.lsGetAndRmFiles(dir.getAbsolutePath());
+
+
+ //Check everything went as expected, and clean up
+ assertEquals(2, rmResults.size());
+ for (Boolean result : rmResults) {
+ assertTrue(result);
+ }
+ assertTrue("Expected remote dir to be empty", dir.delete());
+ assertTrue("Could note delete retrieved file", new File(new File(tmpDir), "1.ftptest").delete());
+ assertTrue("Could note delete retrieved file", new File(new File(tmpDir), "2.ftptest").delete());
+ } finally {
+ ctx.close();
+ }
+ }
+}
+
+
+
diff --git a/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/ToSftpFlowGateway.java b/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/ToSftpFlowGateway.java
new file mode 100644
index 00000000..38a43085
--- /dev/null
+++ b/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/ToSftpFlowGateway.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2002-2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.integration.samples.sftp;
+
+import java.util.List;
+
+/**
+ * @author Gary Russell
+ * @since 2.1
+ *
+ */
+public interface ToSftpFlowGateway {
+
+ public List lsGetAndRmFiles(String dir);
+}
diff --git a/basic/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundGatewaySample-context.xml b/basic/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundGatewaySample-context.xml
new file mode 100644
index 00000000..9ef3195b
--- /dev/null
+++ b/basic/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundGatewaySample-context.xml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/basic/sftp/src/test/resources/log4j.properties b/basic/sftp/src/test/resources/log4j.properties
index 94686dac..d85acd8e 100644
--- a/basic/sftp/src/test/resources/log4j.properties
+++ b/basic/sftp/src/test/resources/log4j.properties
@@ -5,5 +5,6 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
log4j.category.org.springframework=WARN
+log4j.category.org.springframework.integration=DEBUG
log4j.category.org.springframework.integration.sftp=TRACE
log4j.category.org.springframework.integration.samples.sftp=TRACE
diff --git a/basic/sftp/src/test/resources/user.properties b/basic/sftp/src/test/resources/user.properties
index 986067f9..72d8a131 100644
--- a/basic/sftp/src/test/resources/user.properties
+++ b/basic/sftp/src/test/resources/user.properties
@@ -1,2 +1,4 @@
user=
-passphrase=
\ No newline at end of file
+passphrase=
+#private.keyfile=file:/home/someuser/.ssh/id_rsa
+private.keyfile=classpath:META-INF/keys/sftp_rsa
\ No newline at end of file