Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 89203 invoked from network); 26 May 2004 08:21:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 26 May 2004 08:21:33 -0000 Received: (qmail 23941 invoked by uid 500); 26 May 2004 08:22:09 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 23817 invoked by uid 500); 26 May 2004 08:22:07 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 23774 invoked by uid 500); 26 May 2004 08:22:07 -0000 Received: (qmail 23716 invoked by uid 98); 26 May 2004 08:22:06 -0000 Received: from imario@apache.org by hermes.apache.org by uid 82 with qmail-scanner-1.20 (clamuko: 0.70. Clear:RC:0(209.237.227.194):. Processed in 0.875762 secs); 26 May 2004 08:22:06 -0000 X-Qmail-Scanner-Mail-From: imario@apache.org via hermes.apache.org X-Qmail-Scanner: 1.20 (Clear:RC:0(209.237.227.194):. Processed in 0.875762 secs) Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by hermes.apache.org with SMTP; 26 May 2004 08:22:04 -0000 Received: (qmail 88882 invoked by uid 1850); 26 May 2004 08:21:18 -0000 Date: 26 May 2004 08:21:18 -0000 Message-ID: <20040526082118.88881.qmail@minotaur.apache.org> From: imario@apache.org To: jakarta-commons-sandbox-cvs@apache.org Subject: cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp FtpFileSystem.java X-Spam-Rating: hermes.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N imario 2004/05/26 01:21:18 Modified: vfs/src/java/org/apache/commons/vfs/provider/ftp FtpFileSystem.java Log: moved create of ftpclient to its own factory Revision Changes Path 1.29 +19 -96 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java Index: FtpFileSystem.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- FtpFileSystem.java 19 May 2004 19:34:06 -0000 1.28 +++ FtpFileSystem.java 26 May 2004 08:21:18 -0000 1.29 @@ -1,12 +1,12 @@ /* * Copyright 2002, 2003,2004 The Apache Software Foundation. - * + * * Licensed 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. @@ -17,9 +17,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; -import org.apache.commons.net.ftp.FTPReply; import org.apache.commons.vfs.FileName; import org.apache.commons.vfs.FileObject; import org.apache.commons.vfs.FileSystemException; @@ -42,37 +40,21 @@ { private final static Log log = LogFactory.getLog(FtpFileSystem.class); - private final String hostname; - private final int port; - private final String username; - private final String password; +// private final String hostname; +// private final int port; +// private final String username; +// private final String password; // An idle client private FTPClient idleClient; - public FtpFileSystem(final GenericFileName rootName, final FileSystemOptions fileSystemOptions) + public FtpFileSystem(final GenericFileName rootName, final FTPClient ftpClient, final FileSystemOptions fileSystemOptions) { super(rootName, null, fileSystemOptions); - hostname = rootName.getHostName(); - port = rootName.getPort(); + // hostname = rootName.getHostName(); + // port = rootName.getPort(); - // Determine the username and password to use - if (rootName.getUserName() == null) - { - username = "anonymous"; - } - else - { - username = rootName.getUserName(); - } - if (rootName.getPassword() == null) - { - password = "anonymous"; - } - else - { - password = rootName.getPassword(); - } + idleClient = ftpClient; } public void close() @@ -121,7 +103,14 @@ { if (idleClient == null) { - return createConnection(); + final GenericFileName rootName = (GenericFileName) getRoot().getName(); + + return FtpClientFactory.createConnection(rootName.getHostName(), + rootName.getPort(), + rootName.getUserName(), + rootName.getPassword(), + rootName.getPath()); + // return createConnection(); } else { @@ -156,70 +145,4 @@ { return new FtpFileObject(name, this, getRootName()); } - - /** - * Creates a new connection to the server. - */ - private FTPClient createConnection() - throws FileSystemException - { - try - { - final FTPClient client = new FTPClient(); - - /* as soon as commons-1.2 will be released - FTPFileEntryParserFactory myFactory = FtpFileSystemConfigBuilder.getInstance().getFTPFileEntryParserFactory(getFileSystemOptions()); - 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(username, password)) - { - throw new FileSystemException("vfs.provider.ftp/login.error", new Object[]{hostname, username}, null); - } - - // Set binary mode - if (!client.setFileType(FTP.BINARY_FILE_TYPE)) - { - throw new FileSystemException("vfs.provider.ftp/set-binary.error", hostname); - } - - // Change to root by default - // All file operations a relative to the filesystem-root - String root = getRoot().getName().getPath(); - if (root != null) - { - if (!client.changeWorkingDirectory(root)) - { - throw new FileSystemException("vfs.provider/get-attributes-no-exist.error", "/"); - } - } - } - catch (final IOException e) - { - closeConnection(client); - throw e; - } - - return client; - } - catch (final Exception exc) - { - throw new FileSystemException("vfs.provider.ftp/connect.error", new Object[]{hostname}, exc); - } - } - } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org