commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r993534 - in /commons/proper/vfs/trunk/core: ./ src/main/java/org/apache/commons/vfs/impl/ src/main/java/org/apache/commons/vfs/provider/ftp/ src/main/java/org/apache/commons/vfs/provider/ftps/ src/main/java/org/apache/commons/vfs/provider/...
Date Tue, 07 Sep 2010 21:13:19 GMT
Author: jcarman
Date: Tue Sep  7 21:13:19 2010
New Revision: 993534

URL: http://svn.apache.org/viewvc?rev=993534&view=rev
Log:
VFS-264: FTPS Support for VFS

Added:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientFactory.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientWrapper.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileProvider.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileSystemConfigBuilder.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/package.html
Modified:
    commons/proper/vfs/trunk/core/pom.xml
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/impl/providers.xml
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java

Modified: commons/proper/vfs/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/pom.xml?rev=993534&r1=993533&r2=993534&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/pom.xml (original)
+++ commons/proper/vfs/trunk/core/pom.xml Tue Sep  7 21:13:19 2010
@@ -49,6 +49,7 @@
     <dependency>
       <groupId>commons-net</groupId>
       <artifactId>commons-net</artifactId>
+      <version>2.0</version>
       <optional>true</optional>
     </dependency>
     <!--TODO:Revert to [compress] if/when released

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/impl/providers.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/impl/providers.xml?rev=993534&r1=993533&r2=993534&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/impl/providers.xml
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/impl/providers.xml
Tue Sep  7 21:13:19 2010
@@ -51,6 +51,10 @@
         <scheme name="ftp"/>
         <if-available class-name="org.apache.commons.net.ftp.FTPFile"/>
     </provider>
+    <provider class-name="org.apache.commons.vfs.provider.ftps.FtpsFileProvider">
+        <scheme name="ftps"/>
+        <if-available class-name="org.apache.commons.net.ftp.FTPFile"/>
+    </provider>
     <provider class-name="org.apache.commons.vfs.provider.http.HttpFileProvider">
         <scheme name="http"/>
         <if-available class-name="org.apache.commons.httpclient.HttpClient"/>
@@ -134,4 +138,4 @@
         <mime-type name="application/x-tgz" />
     </filter-map>
     -->
-</providers>
\ No newline at end of file
+</providers>

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java?rev=993534&r1=993533&r2=993534&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java
Tue Sep  7 21:13:19 2010
@@ -35,8 +35,7 @@ import java.util.Collection;
  * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  * @version $Revision$ $Date$
  */
-public class FtpFileSystem
-    extends AbstractFileSystem
+public class FtpFileSystem extends AbstractFileSystem
 {
     private static final Log LOG = LogFactory.getLog(FtpFileSystem.class);
 
@@ -48,8 +47,7 @@ public class FtpFileSystem
     // An idle client
     private FtpClient idleClient;
 
-    protected FtpFileSystem(final GenericFileName rootName, final FtpClient ftpClient,
-                            final FileSystemOptions fileSystemOptions)
+    public FtpFileSystem(final GenericFileName rootName, final FtpClient ftpClient, final
FileSystemOptions fileSystemOptions)
     {
         super(rootName, null, fileSystemOptions);
         // hostname = rootName.getHostName();

Added: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientFactory.java?rev=993534&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientFactory.java
(added)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientFactory.java
Tue Sep  7 21:13:19 2010
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.vfs.provider.ftps;
+
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPSClient;
+import org.apache.commons.net.ftp.FTPClientConfig;
+import org.apache.commons.net.ftp.FTPReply;
+import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.util.UserAuthenticatorUtils;
+
+import java.io.IOException;
+
+/**
+ * Create a FtpClient instance
+ *
+ * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
+ * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
+ */
+public class FtpsClientFactory
+{
+    private FtpsClientFactory()
+    {
+    }
+
+    /**
+     * Creates a new connection to the server.
+     */
+    public static FTPSClient createConnection(String hostname, int port, char[] username,
char[] password, String workingDirectory, FileSystemOptions fileSystemOptions) throws FileSystemException
+    {
+        // Determine the username and password to use
+        if (username == null)
+        {
+            username = "anonymous".toCharArray();
+        }
+
+        if (password == null)
+        {
+            password = "anonymous".toCharArray();
+        }
+
+        try
+        {
+            
+            final FTPSClient client;
+          
+            if (FtpsFileSystemConfigBuilder.getInstance().getFtpsType(fileSystemOptions).equals("explicit"))
+              client = new FTPSClient();
+            else if (FtpsFileSystemConfigBuilder.getInstance().getFtpsType(fileSystemOptions).equals("implicit"))
+              client = new FTPSClient(true);
+            else
+              throw new FileSystemException("Invalid FTPS type of "+FtpsFileSystemConfigBuilder.getInstance().getFtpsType(fileSystemOptions)+"
specified. Must be 'implicit' or 'explicit'");
+          
+            String key = FtpsFileSystemConfigBuilder.getInstance().getEntryParser(fileSystemOptions);
+            if (key != null)
+            {
+            	FTPClientConfig config = new FTPClientConfig(key);
+            	
+            	String serverLanguageCode = FtpsFileSystemConfigBuilder.getInstance().getServerLanguageCode(fileSystemOptions);
+            	if (serverLanguageCode != null)
+            	{
+            		config.setServerLanguageCode(serverLanguageCode);
+            	}
+            	String defaultDateFormat = FtpsFileSystemConfigBuilder.getInstance().getDefaultDateFormat(fileSystemOptions);
+            	if (defaultDateFormat != null)
+            	{
+            		config.setDefaultDateFormatStr(defaultDateFormat);
+            	}
+            	String recentDateFormat = FtpsFileSystemConfigBuilder.getInstance().getRecentDateFormat(fileSystemOptions);
+            	if (recentDateFormat != null)
+            	{
+            		config.setRecentDateFormatStr(recentDateFormat);
+            	}
+            	String serverTimeZoneId = FtpsFileSystemConfigBuilder.getInstance().getServerTimeZoneId(fileSystemOptions);
+            	if (serverTimeZoneId != null)
+            	{
+            		config.setServerTimeZoneId(serverTimeZoneId);
+            	}
+            	String[] shortMonthNames = FtpsFileSystemConfigBuilder.getInstance().getShortMonthNames(fileSystemOptions);
+            	if (shortMonthNames != null)
+            	{
+            		StringBuffer shortMonthNamesStr = new StringBuffer(40);
+            		for (int i = 0; i<shortMonthNames.length; i++)
+            		{
+            			if (shortMonthNamesStr.length()>0)
+            			{
+            				shortMonthNamesStr.append("|");
+            			}
+            			shortMonthNamesStr.append(shortMonthNames[i]);            			
+            		}
+            		config.setShortMonthNames(shortMonthNamesStr.toString());
+            	}
+            	
+            	client.configure(config);
+            }
+            
+            FTPFileEntryParserFactory myFactory = FtpsFileSystemConfigBuilder.getInstance().getEntryParserFactory(fileSystemOptions);
+            if (myFactory != null)
+            {
+                client.setParserFactory(myFactory);
+            }
+
+            try
+            {
+                client.connect(hostname, port);
+
+                int reply = client.getReplyCode();
+                if (!FTPReply.isPositiveCompletion(reply))
+                {
+                    throw new FileSystemException("vfs.provider.ftp/connect-rejected.error",
hostname);
+                }
+
+                // Login
+                if (!client.login(
+					UserAuthenticatorUtils.toString(username),
+					UserAuthenticatorUtils.toString(password)))
+                {
+                    throw new FileSystemException("vfs.provider.ftp/login.error", new Object[]{hostname,
UserAuthenticatorUtils.toString(username)}, null);
+                }
+
+                // Set binary mode
+                if (!client.setFileType(FTP.BINARY_FILE_TYPE))
+                {
+                    throw new FileSystemException("vfs.provider.ftp/set-binary.error", hostname);
+                }
+
+                // Set dataTimeout value
+                Integer dataTimeout = FtpsFileSystemConfigBuilder.getInstance().getDataTimeout(fileSystemOptions);
+                if (dataTimeout != null)
+                {
+                    client.setDataTimeout(dataTimeout.intValue());
+                }
+
+                // Change to root by default
+                // All file operations a relative to the filesystem-root
+                // String root = getRoot().getName().getPath();
+
+                Boolean userDirIsRoot = FtpsFileSystemConfigBuilder.getInstance().getUserDirIsRoot(fileSystemOptions);
+                if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue()))
+                {
+                    if (!client.changeWorkingDirectory(workingDirectory))
+                    {
+                        throw new FileSystemException("vfs.provider.ftp/change-work-directory.error",
workingDirectory);
+                    }
+                }
+
+                Boolean passiveMode = FtpsFileSystemConfigBuilder.getInstance().getPassiveMode(fileSystemOptions);
+                if (passiveMode != null && passiveMode.booleanValue())
+                {
+                    client.enterLocalPassiveMode();
+                }
+            }
+            catch (final IOException e)
+            {
+                if (client.isConnected())
+                {
+                    client.disconnect();
+                }
+                throw e;
+            }
+
+            return client;
+        }
+        catch (final Exception exc)
+        {
+            throw new FileSystemException("vfs.provider.ftp/connect.error", new Object[]{hostname},
exc);
+        }
+    }
+}

Added: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientWrapper.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientWrapper.java?rev=993534&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientWrapper.java
(added)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientWrapper.java
Tue Sep  7 21:13:19 2010
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.vfs.provider.ftps;
+
+
+import org.apache.commons.net.ftp.FTPSClient;
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.UserAuthenticationData;
+import org.apache.commons.vfs.util.UserAuthenticatorUtils;
+import org.apache.commons.vfs.provider.GenericFileName;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.commons.vfs.provider.ftp.FtpClient;
+
+
+/**
+ * A wrapper to the FTPClient to allow automatic reconnect on connection loss.<br />
+ * I decided to not to use eg. noop() to determine the state of the connection to avoid unnecesary
server round-trips.
+ */
+class FtpsClientWrapper implements FtpClient
+{
+    private final GenericFileName root;
+    private final FileSystemOptions fileSystemOptions;
+
+    private FTPSClient ftpClient = null;
+    
+    FtpsClientWrapper(final GenericFileName root, final FileSystemOptions fileSystemOptions)
throws FileSystemException
+    {
+        this.root = root;
+        this.fileSystemOptions = fileSystemOptions;
+        getFtpsClient(); // fail-fast
+    }
+
+    public GenericFileName getRoot()
+    {
+        return root;
+    }
+
+    public FileSystemOptions getFileSystemOptions()
+    {
+        return fileSystemOptions;
+    }
+
+    private FTPSClient createClient() throws FileSystemException
+    {
+        final GenericFileName rootName = getRoot();
+
+		UserAuthenticationData authData = null;
+		try
+		{
+			authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, FtpsFileProvider.AUTHENTICATOR_TYPES);
+
+			return FtpsClientFactory.createConnection(rootName.getHostName(),
+				rootName.getPort(),
+				UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())),
+				UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())),
+				rootName.getPath(),
+				getFileSystemOptions());
+		}
+		finally
+		{
+			UserAuthenticatorUtils.cleanup(authData);
+		}
+	}
+
+	private FTPSClient getFtpsClient() throws FileSystemException
+    {
+        if (ftpClient == null)
+        {
+            ftpClient = createClient();
+        }
+
+        return ftpClient;
+    }
+
+    public boolean isConnected() throws FileSystemException
+    {
+        return getFtpsClient().isConnected();
+    }
+
+    public void disconnect() throws IOException
+    {
+        try
+        {
+            getFtpsClient().disconnect();
+        }
+        finally
+        {
+            ftpClient = null;
+        }
+    }
+
+    public FTPFile[] listFiles(String relPath) throws IOException
+    {
+        try
+        {
+            return getFtpsClient().listFiles(relPath);
+        }
+        catch (IOException e)
+        {
+            disconnect();
+            return getFtpsClient().listFiles(relPath);
+        }
+    }
+
+    public boolean removeDirectory(String relPath) throws IOException
+    {
+        try
+        {
+            return getFtpsClient().removeDirectory(relPath);
+        }
+        catch (IOException e)
+        {
+            disconnect();
+            return getFtpsClient().removeDirectory(relPath);
+        }
+    }
+
+    public boolean deleteFile(String relPath) throws IOException
+    {
+        try
+        {
+            return getFtpsClient().deleteFile(relPath);
+        }
+        catch (IOException e)
+        {
+            disconnect();
+            return getFtpsClient().deleteFile(relPath);
+        }
+    }
+
+    public boolean rename(String oldName, String newName) throws IOException
+    {
+        try
+        {
+            return getFtpsClient().rename(oldName, newName);
+        }
+        catch (IOException e)
+        {
+            disconnect();
+            return getFtpsClient().rename(oldName, newName);
+        }
+    }
+
+    public boolean makeDirectory(String relPath) throws IOException
+    {
+        try
+        {
+            return getFtpsClient().makeDirectory(relPath);
+        }
+        catch (IOException e)
+        {
+            disconnect();
+            return getFtpsClient().makeDirectory(relPath);
+        }
+    }
+
+    public boolean completePendingCommand() throws IOException
+    {
+        if (ftpClient != null)
+        {
+            return getFtpsClient().completePendingCommand();
+        }
+
+        return true;
+    }
+
+    public InputStream retrieveFileStream(String relPath) throws IOException
+    {
+        try
+        {
+            return getFtpsClient().retrieveFileStream(relPath);
+        }
+        catch (IOException e)
+        {
+            disconnect();
+            return getFtpsClient().retrieveFileStream(relPath);
+        }
+    }
+
+    public InputStream retrieveFileStream(String relPath, long restartOffset) throws IOException
+    {
+        try
+        {
+            FTPSClient client = getFtpsClient();
+            client.setRestartOffset(restartOffset);
+            return client.retrieveFileStream(relPath);
+        }
+        catch (IOException e)
+        {
+            disconnect();
+
+            FTPSClient client = getFtpsClient();
+            client.setRestartOffset(restartOffset);
+            return client.retrieveFileStream(relPath);
+        }
+    }
+
+    public OutputStream appendFileStream(String relPath) throws IOException
+    {
+        try
+        {
+            return getFtpsClient().appendFileStream(relPath);
+        }
+        catch (IOException e)
+        {
+            disconnect();
+            return getFtpsClient().appendFileStream(relPath);
+        }
+    }
+
+    public OutputStream storeFileStream(String relPath) throws IOException
+    {
+        try
+        {
+            return getFtpsClient().storeFileStream(relPath);
+        }
+        catch (IOException e)
+        {
+            disconnect();
+            return getFtpsClient().storeFileStream(relPath);
+        }
+    }
+
+    public boolean abort() throws IOException
+    {
+        try
+        {
+            // imario@apache.org: 2005-02-14
+            // it should be better to really "abort" the transfer, but
+            // currently I didnt manage to make it work - so lets "abort" the hard way.
+            // return getFtpsClient().abort();
+
+            disconnect();
+            return true;
+        }
+        catch (IOException e)
+        {
+            disconnect();
+        }
+        return true;
+    }
+
+    public String getReplyString() throws IOException
+    {
+        return getFtpsClient().getReplyString();
+    }
+}

Added: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileProvider.java?rev=993534&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileProvider.java
(added)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileProvider.java
Tue Sep  7 21:13:19 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.vfs.provider.ftps;
+
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileSystem;
+import org.apache.commons.vfs.FileSystemConfigBuilder;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.provider.GenericFileName;
+
+import org.apache.commons.vfs.provider.ftp.FtpFileProvider;
+import org.apache.commons.vfs.provider.ftp.FtpFileSystem;
+
+/**
+ * A provider for FTP file systems.
+ * 
+ * NOTE: Most of the heavy lifting for FTPS is done by the org.apache.commons.vfs.provider.ftp
package since 
+ * they both use commons-net package
+ *
+ * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
+ * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
+ */
+public class FtpsFileProvider extends FtpFileProvider
+{
+	public FtpsFileProvider()
+    {
+        super();
+    }
+
+    /**
+     * Creates the filesystem.
+     */
+    protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions
fileSystemOptions)
+        throws FileSystemException
+    {
+        // Create the file system
+        final GenericFileName rootName = (GenericFileName) name;
+
+        FtpsClientWrapper ftpClient = new FtpsClientWrapper(rootName, fileSystemOptions);
+
+        return new FtpFileSystem(rootName, ftpClient, fileSystemOptions);
+    }
+
+    public FileSystemConfigBuilder getConfigBuilder()
+    {
+        return FtpsFileSystemConfigBuilder.getInstance();
+    }
+}

Added: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileSystemConfigBuilder.java?rev=993534&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileSystemConfigBuilder.java
(added)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileSystemConfigBuilder.java
Tue Sep  7 21:13:19 2010
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.vfs.provider.ftps;
+
+import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
+import org.apache.commons.vfs.FileSystemConfigBuilder;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.provider.ftp.FtpFileSystem;
+
+/**
+ * The config builder for various ftp configuration options
+ *
+ * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
+ * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
+ */
+public class FtpsFileSystemConfigBuilder extends FileSystemConfigBuilder {
+  private final static FtpsFileSystemConfigBuilder builder =
+    new FtpsFileSystemConfigBuilder();
+
+  private final static String FACTORY_KEY =
+    FTPFileEntryParserFactory.class.getName() + ".KEY";
+  private final static String PASSIVE_MODE =
+    FtpsFileSystemConfigBuilder.class.getName() + ".PASSIVE";
+  private final static String USER_DIR_IS_ROOT =
+    FtpsFileSystemConfigBuilder.class.getName() + ".USER_DIR_IS_ROOT";
+  private final static String DATA_TIMEOUT =
+    FtpsFileSystemConfigBuilder.class.getName() + ".DATA_TIMEOUT";
+  private final static String FTPS_TYPE =
+    FtpsFileSystemConfigBuilder.class.getName() + ".FTPS_TYPE";
+
+  private final static String SERVER_LANGUAGE_CODE =
+    FtpsFileSystemConfigBuilder.class.getName() + ".SERVER_LANGUAGE_CODE";
+  private final static String DEFAULT_DATE_FORMAT =
+    FtpsFileSystemConfigBuilder.class.getName() + ".DEFAULT_DATE_FORMAT";
+  private final static String RECENT_DATE_FORMAT =
+    FtpsFileSystemConfigBuilder.class.getName() + ".RECENT_DATE_FORMAT";
+  private final static String SERVER_TIME_ZONE_ID =
+    FtpsFileSystemConfigBuilder.class.getName() + ".SERVER_TIME_ZONE_ID";
+  private final static String SHORT_MONTH_NAMES =
+    FtpsFileSystemConfigBuilder.class.getName() + ".SHORT_MONTH_NAMES";
+
+  public static FtpsFileSystemConfigBuilder getInstance() {
+    return builder;
+  }
+
+  private FtpsFileSystemConfigBuilder() {
+  }
+
+  /**
+   * FTPFileEntryParserFactory which will be used for ftp-entry parsing
+   *
+   * @param opts
+   * @param factory instance of your factory
+   */
+  public void setEntryParserFactory(FileSystemOptions opts,
+                                    FTPFileEntryParserFactory factory) {
+    setParam(opts, FTPFileEntryParserFactory.class.getName(), factory);
+  }
+
+  /**
+   * @param opts
+   * @see #setEntryParserFactory
+   */
+  public FTPFileEntryParserFactory getEntryParserFactory(FileSystemOptions opts) {
+    return (FTPFileEntryParserFactory)getParam(opts,
+                                               FTPFileEntryParserFactory.class.getName());
+  }
+
+  /**
+   * set the FQCN of your FileEntryParser used to parse the directory listing from your server.<br
/>
+   * <br />
+   * <i>If you do not use the default commons-net FTPFileEntryParserFactory e.g. by
using {@link #setEntryParserFactory}
+   * this is the "key" parameter passed as argument into your custom factory</i>
+   *
+   * @param opts
+   * @param key
+   */
+  public void setEntryParser(FileSystemOptions opts, String key) {
+    setParam(opts, FACTORY_KEY, key);
+  }
+
+  /**
+   * @param opts
+   * @see #setEntryParser
+   */
+  public String getEntryParser(FileSystemOptions opts) {
+    return (String)getParam(opts, FACTORY_KEY);
+  }
+
+  protected Class getConfigClass() {
+    return FtpFileSystem.class;
+  }
+
+  /**
+   * enter into passive mode
+   *
+   * @param opts
+   * @param passiveMode
+   */
+  public void setPassiveMode(FileSystemOptions opts, boolean passiveMode) {
+    setParam(opts, PASSIVE_MODE, passiveMode ? Boolean.TRUE : Boolean.FALSE);
+  }
+
+  /**
+   * @param opts
+   * @see #setPassiveMode
+   */
+  public Boolean getPassiveMode(FileSystemOptions opts) {
+    return (Boolean)getParam(opts, PASSIVE_MODE);
+  }
+
+  /**
+   * use user directory as root (do not change to fs root)
+   *
+   * @param opts
+   * @param userDirIsRoot
+   */
+  public void setUserDirIsRoot(FileSystemOptions opts, boolean userDirIsRoot) {
+    setParam(opts, USER_DIR_IS_ROOT,
+             userDirIsRoot ? Boolean.TRUE : Boolean.FALSE);
+  }
+
+  /**
+   * @param opts
+   * @see #setUserDirIsRoot
+   */
+  public Boolean getUserDirIsRoot(FileSystemOptions opts) {
+    return getBoolean(opts, USER_DIR_IS_ROOT, Boolean.TRUE);
+  }
+
+  /**
+   * Set FTPS type, either "implicit" or "explicit"
+   *
+   * @param opts
+   * @param ftpsType
+   */
+  public void setFtpsType(FileSystemOptions opts, String ftpsType) {
+    setParam(opts, USER_DIR_IS_ROOT, ftpsType);
+  }
+
+  /**
+   * @param opts
+   * @see #setFtpsType
+   */
+  public String getFtpsType(FileSystemOptions opts) {
+    return getString(opts, FTPS_TYPE, "explicit");
+  }
+
+  /**
+   * @param opts
+   * @see #setDataTimeout
+   */
+  public Integer getDataTimeout(FileSystemOptions opts) {
+    return (Integer)getParam(opts, DATA_TIMEOUT);
+  }
+
+  /**
+   * set the data timeout for the ftp client.<br />
+   * If you set the dataTimeout to <code>null</code> no dataTimeout will be set
on the
+   * ftp client.
+   *
+   * @param opts
+   * @param dataTimeout
+   */
+  public void setDataTimeout(FileSystemOptions opts, Integer dataTimeout) {
+    setParam(opts, DATA_TIMEOUT, dataTimeout);
+  }
+
+  /**
+   * get the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
+   * for details and examples.
+   */
+  public String getServerLanguageCode(FileSystemOptions opts) {
+    return (String)getParam(opts, SERVER_LANGUAGE_CODE);
+  }
+
+  /**
+   * set the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
+   * for details and examples.
+   */
+  public void setServerLanguageCode(FileSystemOptions opts,
+                                    String serverLanguageCode) {
+    setParam(opts, SERVER_LANGUAGE_CODE, serverLanguageCode);
+  }
+
+  /**
+   * get the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
+   * for details and examples.
+   */
+  public String getDefaultDateFormat(FileSystemOptions opts) {
+    return (String)getParam(opts, DEFAULT_DATE_FORMAT);
+  }
+
+  /**
+   * set the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
+   * for details and examples.
+   */
+  public void setDefaultDateFormat(FileSystemOptions opts,
+                                   String defaultDateFormat) {
+    setParam(opts, DEFAULT_DATE_FORMAT, defaultDateFormat);
+  }
+
+  /**
+   * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
+   */
+  public String getRecentDateFormat(FileSystemOptions opts) {
+    return (String)getParam(opts, RECENT_DATE_FORMAT);
+  }
+
+  /**
+   * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
+   */
+  public void setRecentDateFormat(FileSystemOptions opts,
+                                  String recentDateFormat) {
+    setParam(opts, RECENT_DATE_FORMAT, recentDateFormat);
+  }
+
+  /**
+   * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
+   */
+  public String getServerTimeZoneId(FileSystemOptions opts) {
+    return (String)getParam(opts, SERVER_TIME_ZONE_ID);
+  }
+
+  /**
+   * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
+   */
+  public void setServerTimeZoneId(FileSystemOptions opts,
+                                  String serverTimeZoneId) {
+    setParam(opts, SERVER_TIME_ZONE_ID, serverTimeZoneId);
+  }
+
+  /**
+   * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
+   */
+  public String[] getShortMonthNames(FileSystemOptions opts) {
+    return (String[])getParam(opts, SHORT_MONTH_NAMES);
+  }
+
+  /**
+   * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
+   */
+  public void setShortMonthNames(FileSystemOptions opts,
+                                 String[] shortMonthNames) {
+    String[] clone = null;
+    if (shortMonthNames != null) {
+      clone = new String[shortMonthNames.length];
+      System.arraycopy(shortMonthNames, 0, clone, 0, shortMonthNames.length);
+    }
+
+    setParam(opts, SHORT_MONTH_NAMES, clone);
+  }
+}

Added: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/package.html
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/package.html?rev=993534&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/package.html
(added)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/package.html
Tue Sep  7 21:13:19 2010
@@ -0,0 +1,19 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+-->
+<body>
+<p>The FTPS File Provider.</p>
+</body>

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java?rev=993534&r1=993533&r2=993534&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java
Tue Sep  7 21:13:19 2010
@@ -214,7 +214,7 @@ public final class SftpFileSystemConfigB
      */
     public String getStrictHostKeyChecking(FileSystemOptions opts)
     {
-        return getString(opts, "StrictHostKeyChecking");
+        return getString(opts, "StrictHostKeyChecking", "no");
     }
 
     /**
@@ -235,7 +235,7 @@ public final class SftpFileSystemConfigB
      */
     public Boolean getUserDirIsRoot(FileSystemOptions opts)
     {
-        return getBoolean(opts, USER_DIR_IS_ROOT);
+        return getBoolean(opts, USER_DIR_IS_ROOT, Boolean.TRUE);
     }
 
     /**



Mime
View raw message