⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftpclient.java

📁 java编写的非常详尽的基于ftp协议的上传下载源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/**
 *
 *  edtFTPj
 *
 *  Copyright (C) 2000-2003  Enterprise Distributed Technologies Ltd
 *
 *  www.enterprisedt.com
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Bug fixes, suggestions and comments should be should posted on 
 *  http://www.enterprisedt.com/forums/index.php
 *
 *  Change Log:
 *
 *        $Log: FTPClient.java,v $
 *        Revision 1.97  2008-05-22 04:20:55  bruceb
 *        moved stuff to internal etc
 *
 *        Revision 1.96  2008-05-02 07:41:30  bruceb
 *        setModTime added
 *
 *        Revision 1.95  2008-03-13 04:23:29  bruceb
 *        changed to system()
 *
 *        Revision 1.94  2008-03-13 00:22:14  bruceb
 *        added executeCommand
 *
 *        Revision 1.93  2008-01-09 03:54:21  bruceb
 *        executeCommand() now returns reply code
 *
 *        Revision 1.92  2007-12-18 07:54:58  bruceb
 *        many small changes to prepare for FileTransferClient
 *
 *        Revision 1.91  2007-11-29 02:32:09  hans
 *        Added DEFAULT_LISTING_LOCALES and made related changes to initializers.
 *
 *        Revision 1.90  2007-11-13 07:14:04  bruceb
 *        ListenOnAllInterfaces
 *
 *        Revision 1.89  2007-11-07 23:53:50  bruceb
 *        refactoring for FXP
 *
 *        Revision 1.88  2007-10-12 05:21:13  bruceb
 *        can set multiple locales (and 2 set by default)
 *
 *        Revision 1.87  2007-08-15 03:47:39  bruceb
 *        fix separator
 *
 *        Revision 1.86  2007-08-09 00:50:20  bruceb
 *        added 250 reply to some commands
 *
 *        Revision 1.85  2007-08-07 04:46:25  bruceb
 *        added counts for transfers and deletes plus getLastReply()
 *
 *        Revision 1.84  2007-07-18 02:16:33  bruceb
 *        ignore size() exception in resume
 *
 *        Revision 1.83  2007-07-05 05:28:27  bruceb
 *        add getters for message collections
 *
 *        Revision 1.82  2007-06-14 04:12:48  bruceb
 *        added setForceUniqueNames()
 *
 *        Revision 1.81  2007-06-06 22:20:11  bruceb
 *        FTP_LINE_SEPARATOR now public
 *
 *        Revision 1.80  2007-05-29 04:17:24  bruceb
 *        modify connected() method, and null out control when quitting
 *
 *        Revision 1.79  2007-05-15 01:02:58  bruceb
 *        file factory change if syst doesn't work
 *
 *        Revision 1.78  2007/04/24 01:58:03  bruceb
 *        more debug for validateTransferOnError
 *
 *        Revision 1.77  2007/04/23 23:43:20  bruceb
 *        check on dirname in dirDetails()
 *
 *        Revision 1.76  2007/04/21 04:24:46  bruceb
 *        fix to cope with any ascii file
 *
 *        Revision 1.75  2007/03/22 04:03:47  bruceb
 *        added getOutputStream()
 *
 *        Revision 1.74  2007/03/19 22:07:36  bruceb
 *        set control to null
 *
 *        Revision 1.73  2007/03/13 02:45:08  bruceb
 *        deleteOnFailure flag added
 *
 *        Revision 1.72  2007/03/09 05:04:01  bruceb
 *        fixed bugs in ASCII put & get
 *
 *        Revision 1.71  2007/02/26 07:17:54  bruceb
 *        make various method package or protected visibility so they can be accessed by subclasses etc
 *
 *        Revision 1.70  2007/02/07 23:02:26  bruceb
 *        fixed failure to throw cancellation exception
 *
 *        Revision 1.69  2007/02/06 07:19:24  bruceb
 *        fixed autodetect bug re actual mode not being changed on the server
 *
 *        Revision 1.68  2007/02/04 23:02:40  bruceb
 *        more error logging and extra codes, set strict validation off
 *
 *        Revision 1.67  2007/02/01 06:05:18  bruceb
 *        enable cancelling of large directory listings
 *
 *        Revision 1.66  2007/01/15 23:05:14  bruceb
 *        added fileDetails()
 *
 *        Revision 1.65  2007/01/12 02:04:56  bruceb
 *        extracted string matchers & fixed exists()
 *
 *        Revision 1.64  2007/01/10 02:37:39  bruceb
 *        modify exists to use RETR if necessary
 *
 *        Revision 1.63  2006/12/12 01:04:54  hans
 *        Fixed bug in exists method and added logging of raw directory listing.
 *
 *        Revision 1.62  2006/10/27 15:44:06  bruceb
 *        added sendServerWakeup()
 *
 *        Revision 1.61  2006/10/17 11:03:41  bruceb
 *        fix setActivePortRange comment, include using single port info
 *
 *        Revision 1.60  2006/10/17 10:28:43  bruceb
 *        refactored to get setupDataSocket()
 *
 *        Revision 1.59  2006/10/11 08:38:00  bruceb
 *        controlEncoding applied to directory listings
 *
 *        Revision 1.58  2006/09/11 12:34:00  bruceb
 *        added exists() method
 *
 *        Revision 1.57  2006/08/23 08:48:51  bruceb
 *        don't null out FileFactory when quit() is called
 *
 *        Revision 1.56  2006/07/27 14:12:01  bruceb
 *        IPV6 changes and fixed bug re control channel messages after unexpected close on data connection
 *
 *        Revision 1.55  2006/05/22 01:54:42  hans
 *        Made remoteHost protected.
 *
 *        Revision 1.54  2006/02/16 19:47:09  hans
 *        Added comment
 *
 *        Revision 1.53  2005/11/15 21:02:32  bruceb
 *        more debug
 *
 *        Revision 1.52  2005/11/10 19:46:13  bruceb
 *        delegate resume comments to FTPClientInterface
 *
 *        Revision 1.51  2005/11/10 13:40:28  bruceb
 *        more elaborate versioning info to debug
 *
 *        Revision 1.50  2005/11/09 21:15:38  bruceb
 *        autodetect file types
 *
 *        Revision 1.49  2005/10/10 20:42:56  bruceb
 *        append now in FTPClientInterface
 *
 *        Revision 1.48  2005/09/29 16:03:06  bruceb
 *        permit 350 return from STOR
 *
 *        Revision 1.47  2005/09/21 10:38:06  bruceb
 *        fix for LIST error re empty dir (proFTPD/TLS)
 *
 *        Revision 1.46  2005/09/20 09:44:36  bruceb
 *        extra no files found string, SYST accepts 213
 *
 *        Revision 1.45  2005/09/02 21:03:04  bruceb
 *        no abort() with cancel
 *
 *        Revision 1.44  2005/08/26 17:48:16  bruceb
 *        passive ip address setting + ASCII optimisation
 *
 *        Revision 1.43  2005/06/17 18:25:56  bruceb
 *        fix javadoc
 *
 *        Revision 1.42  2005/06/16 21:39:49  hans
 *        deprecated ControlPort accessors and removed comments for FTPClientInterface methods
 *
 *        Revision 1.41  2005/06/10 15:44:38  bruceb
 *        added noOperation() and connected()
 *
 *        Revision 1.40  2005/06/03 11:25:17  bruceb
 *        ascii fixes, setActivePortRange
 *
 *        Revision 1.41  2005/05/24 11:32:28  bruceb
 *        version + timestamp info in static block
 *
 *        Revision 1.40  2005/05/15 19:46:28  bruceb
 *        changes for testing setActivePortRange + STOR accepting 350 nonstrict
 *
 *        Revision 1.39  2005/04/01 13:58:15  bruceb
 *        restructured dir() exception handling + quote() change
 *
 *        Revision 1.38  2005/03/18 11:04:32  bruceb
 *        deprecated constructors
 *
 *        Revision 1.37  2005/03/11 14:40:11  bruceb
 *        added cdup() and changed buffer defaults
 *
 *        Revision 1.36  2005/03/03 21:07:14  bruceb
 *        implement interface & augment login doco
 *
 *        Revision 1.35  2005/02/04 12:40:35  bruceb
 *        tidied javadoc
 *
 *        Revision 1.34  2005/02/04 12:28:51  bruceb
 *        when getting, if file exists and is readonly, exception is thrown
 *
 *        Revision 1.33  2005/01/28 13:55:39  bruceb
 *        added ACCT handling
 *
 *        Revision 1.32  2005/01/14 20:27:02  bruceb
 *        exception restructuring + ABOR
 *
 *        Revision 1.31  2004/11/19 08:28:10  bruceb
 *        added setPORTIP()
 *
 *        Revision 1.30  2004/10/18 15:54:48  bruceb
 *        clearSOCKS added, set encoding for control sock, locale for parser
 *
 *        Revision 1.29  2004/09/21 21:28:28  bruceb
 *        fixed javadoc comment
 *
 *        Revision 1.28  2004/09/18 14:27:57  bruceb
 *        features() throw exception if not supported
 *
 *        Revision 1.27  2004/09/18 09:33:47  bruceb
 *        1.1.8 tweaks
 *
 *        Revision 1.26  2004/09/17 14:12:38  bruceb
 *        fixed javadoc re filemasks
 *
 *        Revision 1.25  2004/09/14 06:24:03  bruceb
 *        fixed javadoc comment
 *
 *        Revision 1.24  2004/08/31 13:48:29  bruceb
 *        resume,features,restructure
 *
 *        Revision 1.23  2004/07/23 08:34:32  bruceb
 *        strict replies or not, better tfr monitor reporting
 *
 *        Revision 1.22  2004/06/25 11:47:46  bruceb
 *        made 1.1.x compatible
 *
 *        Revision 1.21  2004/06/11 10:20:35  bruceb
 *        permit 200 to be returned from various cmds
 *
 *        Revision 1.20  2004/05/22 16:52:57  bruceb
 *        message listener
 *
 *        Revision 1.19  2004/05/15 22:37:22  bruceb
 *        put debugResponses back in
 *
 *        Revision 1.18  2004/05/13 23:00:34  hans
 *        changed comment
 *
 *        Revision 1.17  2004/05/08 21:14:41  bruceb
 *        checkConnection stuff
 *
 *        Revision 1.14  2004/04/19 21:54:06  bruceb
 *        final tweaks to dirDetails() re caching
 *
 *        Revision 1.13  2004/04/18 11:16:44  bruceb
 *        made validateTransfer() public
 *
 *        Revision 1.12  2004/04/17 18:37:38  bruceb
 *        new parse functionality
 *
 *        Revision 1.11  2004/03/23 20:26:49  bruceb
 *        tweak to size(), catch exceptions on puts()
 *
 *        Revision 1.10  2003/11/15 11:23:55  bruceb
 *        changes required for ssl subclasses
 *
 *        Revision 1.6  2003/05/31 14:53:44  bruceb
 *        1.2.2 changes
 *
 *        Revision 1.5  2003/01/29 22:46:08  bruceb
 *        minor changes
 *
 *        Revision 1.4  2002/11/19 22:01:25  bruceb
 *        changes for 1.2
 *
 *        Revision 1.3  2001/10/09 20:53:46  bruceb
 *        Active mode changes
 *
 *        Revision 1.1  2001/10/05 14:42:03  bruceb
 *        moved from old project
 *
 */

package com.enterprisedt.net.ftp;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;
import java.util.Vector;

import com.enterprisedt.net.ftp.internal.FTPDataSocket;
import com.enterprisedt.net.ftp.internal.SocketUtils;
import com.enterprisedt.util.debug.Level;
import com.enterprisedt.util.debug.Logger;

/**
 *  Supports client-side FTP. Most common
 *  FTP operations are present in this class.
 *
 *  @author      Bruce Blackshaw
 *  @version     $Revision: 1.97 $
 */
public class FTPClient implements FTPClientInterface {

    /**
     *  Revision control id
     */
    public static String cvsId = "@(#)$Id: FTPClient.java,v 1.97 2008-05-22 04:20:55 bruceb Exp $";
    
    /**
     * Default byte interval for transfer monitor
     */
    final public static int DEFAULT_MONITOR_INTERVAL = 65535;
    
    /**
     * Default transfer buffer size
     */
    final public static int DEFAULT_BUFFER_SIZE = 16384;
    
    /**
     * Maximum port number
     */
    final private static int MAX_PORT = 65535;
    
    /**
     * Default timeout
     */
    final public static int DEFAULT_TIMEOUT = 60*1000;
    
    /**
     * Short value for a timeout
     */
    final private static int SHORT_TIMEOUT = 500;
    
    /**
     * Default encoding used for control data
     */
    final public static String DEFAULT_ENCODING = "US-ASCII";
    
    /**
     * SOCKS port property name
     */
    final private static String SOCKS_PORT = "socksProxyPort";

    /**
     * SOCKS host property name
     */
    final private static String SOCKS_HOST = "socksProxyHost";
    
    /**
     * Line separator
     */
    final private static byte[] LINE_SEPARATOR = System.getProperty("line.separator").getBytes();
    
    /**
     * Used for ASCII translation
     */
    final public static byte CARRIAGE_RETURN = 13;
    
    
    /**
     * Used for ASCII translation
     */
    final public static byte LINE_FEED = 10;
    
    /**
     * Used for ASCII translation
     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -