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 */ 017package org.apache.commons.vfs2.provider.ftp; 018 019import java.util.Arrays; 020import java.util.Collection; 021import java.util.Collections; 022 023import org.apache.commons.vfs2.Capability; 024import org.apache.commons.vfs2.FileName; 025import org.apache.commons.vfs2.FileSystem; 026import org.apache.commons.vfs2.FileSystemConfigBuilder; 027import org.apache.commons.vfs2.FileSystemException; 028import org.apache.commons.vfs2.FileSystemOptions; 029import org.apache.commons.vfs2.UserAuthenticationData; 030import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider; 031import org.apache.commons.vfs2.provider.GenericFileName; 032 033/** 034 * A provider for FTP file systems. 035 */ 036public class FtpFileProvider extends AbstractOriginatingFileProvider { 037 /** 038 * File Entry Parser. 039 */ 040 public static final String ATTR_FILE_ENTRY_PARSER = "FEP"; 041 042 /** 043 * Authenticator types. 044 */ 045 public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = new UserAuthenticationData.Type[] { 046 UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD }; 047 048 static final Collection<Capability> capabilities = Collections.unmodifiableCollection(Arrays 049 .asList(new Capability[] { Capability.CREATE, Capability.DELETE, Capability.RENAME, Capability.GET_TYPE, 050 Capability.LIST_CHILDREN, Capability.READ_CONTENT, Capability.GET_LAST_MODIFIED, Capability.URI, 051 Capability.WRITE_CONTENT, Capability.APPEND_CONTENT, Capability.RANDOM_ACCESS_READ, })); 052 053 /** 054 * Constructs a new provider. 055 */ 056 public FtpFileProvider() { 057 super(); 058 setFileNameParser(FtpFileNameParser.getInstance()); 059 } 060 061 /** 062 * Creates the filesystem. 063 */ 064 @Override 065 protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions) 066 throws FileSystemException { 067 // Create the file system 068 final GenericFileName rootName = (GenericFileName) name; 069 070 final FTPClientWrapper ftpClient = new FTPClientWrapper(rootName, fileSystemOptions); 071 /* 072 * FTPClient ftpClient = FtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), 073 * rootName.getUserName(), rootName.getPassword(), rootName.getPath(), fileSystemOptions); 074 */ 075 076 return new FtpFileSystem(rootName, ftpClient, fileSystemOptions); 077 } 078 079 @Override 080 public FileSystemConfigBuilder getConfigBuilder() { 081 return FtpFileSystemConfigBuilder.getInstance(); 082 } 083 084 @Override 085 public Collection<Capability> getCapabilities() { 086 return capabilities; 087 } 088}