You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by lh...@apache.org on 2009/02/12 15:41:46 UTC
svn commit: r743767 -
/servicemix/components/bindings/servicemix-ftp/trunk/src/main/java/org/apache/servicemix/ftp/FtpSenderEndpoint.java
Author: lhein
Date: Thu Feb 12 14:41:46 2009
New Revision: 743767
URL: http://svn.apache.org/viewvc?rev=743767&view=rev
Log:
fixed SM-1800
Modified:
servicemix/components/bindings/servicemix-ftp/trunk/src/main/java/org/apache/servicemix/ftp/FtpSenderEndpoint.java
Modified: servicemix/components/bindings/servicemix-ftp/trunk/src/main/java/org/apache/servicemix/ftp/FtpSenderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-ftp/trunk/src/main/java/org/apache/servicemix/ftp/FtpSenderEndpoint.java?rev=743767&r1=743766&r2=743767&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-ftp/trunk/src/main/java/org/apache/servicemix/ftp/FtpSenderEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-ftp/trunk/src/main/java/org/apache/servicemix/ftp/FtpSenderEndpoint.java Thu Feb 12 14:41:46 2009
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
+import java.util.StringTokenizer;
import javax.jbi.JBIException;
import javax.jbi.management.DeploymentException;
@@ -47,7 +48,8 @@
private String uploadPrefix;
private String uploadSuffix;
private boolean checkDuplicates = true;
-
+ private boolean autoCreateDirectory = true;
+
public FtpSenderEndpoint() {
}
@@ -96,6 +98,37 @@
}
}
}
+
+ // borrow client from pool
+ FTPClient ftp = borrowClient();
+ String folderName = "";
+ try {
+ StringTokenizer strTok = null;
+ if (isAutoCreateDirectory() && !ftp.changeWorkingDirectory(getWorkingPath())) {
+ // it seems the folder isn't there, so create it
+ strTok = new StringTokenizer(getWorkingPath(), "/");
+
+ while (strTok.hasMoreTokens()) {
+ folderName += '/';
+ folderName += strTok.nextToken();
+ if (!ftp.changeWorkingDirectory(folderName)) {
+ if (ftp.makeDirectory(folderName)) {
+ // the folder now exists
+ } else {
+ // unable to create the folder
+ throw new IOException("The defined folder " + getWorkingPath() + " doesn't exist on the server and it can't be created automatically.");
+ }
+ }
+ }
+ }
+ } finally {
+ // give back the client
+ returnClient(ftp);
+ }
+ }
+
+ private String getWorkingPath() {
+ return (uri != null && uri.getPath() != null) ? uri.getPath() : ".";
}
// Properties
@@ -164,6 +197,23 @@
public void setUploadSuffix(String uploadSuffix) {
this.uploadSuffix = uploadSuffix;
}
+
+ /**
+ * Specifies if the endpoint should create the target directory, if it does
+ * not already exist. If you set this to <code>false</code> and the
+ * directory does not exist, the endpoint will not do anything. Default
+ * value is <code>true</code>.
+ *
+ * @param autoCreateDirectory a boolean specifying if the endpoint creates
+ * directories.
+ */
+ public void setAutoCreateDirectory(boolean autoCreateDirectory) {
+ this.autoCreateDirectory = autoCreateDirectory;
+ }
+
+ public boolean isAutoCreateDirectory() {
+ return autoCreateDirectory;
+ }
// Implementation methods
//-------------------------------------------------------------------------