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 /** 039 * File Entry Parser. 040 */ 041 public static final String ATTR_FILE_ENTRY_PARSER = "FEP"; 042 043 /** 044 * Authenticator types. 045 */ 046 public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = { 047 UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD }; 048 049 static final Collection<Capability> CAPABILITIES = Collections 050 .unmodifiableCollection(Arrays.asList(Capability.CREATE, Capability.DELETE, Capability.RENAME, 051 Capability.GET_TYPE, Capability.LIST_CHILDREN, Capability.READ_CONTENT, Capability.GET_LAST_MODIFIED, 052 Capability.URI, Capability.WRITE_CONTENT, Capability.APPEND_CONTENT, Capability.RANDOM_ACCESS_READ)); 053 054 /** 055 * Constructs a new provider. 056 */ 057 public FtpFileProvider() { 058 setFileNameParser(FtpFileNameParser.getInstance()); 059 } 060 061 /** 062 * Creates the file system. 063 * 064 * @return a new FileSystem, never null. 065 */ 066 @Override 067 protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions) 068 throws FileSystemException { 069 // Create the file system 070 final GenericFileName rootName = (GenericFileName) name; 071 final FTPClientWrapper ftpClient = new FTPClientWrapper(rootName, fileSystemOptions); 072 /* 073 * FTPClient ftpClient = FtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), 074 * rootName.getUserName(), rootName.getPassword(), rootName.getPath(), fileSystemOptions); 075 */ 076 return new FtpFileSystem(rootName, ftpClient, fileSystemOptions); 077 } 078 079 @Override 080 public Collection<Capability> getCapabilities() { 081 return CAPABILITIES; 082 } 083 084 @Override 085 public FileSystemConfigBuilder getConfigBuilder() { 086 return FtpFileSystemConfigBuilder.getInstance(); 087 } 088}