001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.vfs2.provider.ftp;
018    
019    import java.util.Arrays;
020    import java.util.Collection;
021    import java.util.Collections;
022    
023    import org.apache.commons.vfs2.Capability;
024    import org.apache.commons.vfs2.FileName;
025    import org.apache.commons.vfs2.FileSystem;
026    import org.apache.commons.vfs2.FileSystemConfigBuilder;
027    import org.apache.commons.vfs2.FileSystemException;
028    import org.apache.commons.vfs2.FileSystemOptions;
029    import org.apache.commons.vfs2.UserAuthenticationData;
030    import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider;
031    import org.apache.commons.vfs2.provider.GenericFileName;
032    
033    /**
034     * A provider for FTP file systems.
035     *
036     * @author <a href="http://commons.apache.org/vfs/team-list.html">Commons VFS team</a>
037     */
038    public class FtpFileProvider
039        extends AbstractOriginatingFileProvider
040    {
041        /**
042         * File Entry Parser.
043         */
044        public static final String ATTR_FILE_ENTRY_PARSER = "FEP";
045    
046        /**
047         * Authenticator types.
048         */
049        public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = new UserAuthenticationData.Type[]
050            {
051                UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD
052            };
053    
054        static final Collection<Capability> capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[]
055        {
056            Capability.CREATE,
057            Capability.DELETE,
058            Capability.RENAME,
059            Capability.GET_TYPE,
060            Capability.LIST_CHILDREN,
061            Capability.READ_CONTENT,
062            Capability.GET_LAST_MODIFIED,
063            Capability.URI,
064            Capability.WRITE_CONTENT,
065            Capability.APPEND_CONTENT,
066            Capability.RANDOM_ACCESS_READ,
067        }));
068    
069        public FtpFileProvider()
070        {
071            super();
072            setFileNameParser(FtpFileNameParser.getInstance());
073        }
074    
075        /**
076         * Creates the filesystem.
077         */
078        @Override
079        protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
080            throws FileSystemException
081        {
082            // Create the file system
083            final GenericFileName rootName = (GenericFileName) name;
084    
085            FTPClientWrapper ftpClient = new FTPClientWrapper(rootName, fileSystemOptions);
086            /*
087            FTPClient ftpClient = FtpClientFactory.createConnection(rootName.getHostName(),
088                rootName.getPort(),
089                rootName.getUserName(),
090                rootName.getPassword(),
091                rootName.getPath(),
092                fileSystemOptions);
093            */
094    
095            return new FtpFileSystem(rootName, ftpClient, fileSystemOptions);
096        }
097    
098        @Override
099        public FileSystemConfigBuilder getConfigBuilder()
100        {
101            return FtpFileSystemConfigBuilder.getInstance();
102        }
103    
104        public Collection<Capability> getCapabilities()
105        {
106            return capabilities;
107        }
108    }