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

📄 connectioncontext.java

📁 java编写的非常详尽的基于ftp协议的上传下载源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * 
 *  Copyright (C) 2007 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: ConnectionContext.java,v $
 *    Revision 1.1  2008-05-23 02:45:41  bruceb
 *    moved context
 *
 *    Revision 1.3  2008-05-22 04:20:55  bruceb
 *    moved stuff to internal etc
 *
 *    Revision 1.2  2007-12-20 00:40:16  bruceb
 *    autologin
 *
 *    Revision 1.1  2007-12-18 07:52:06  bruceb
 *    2.0 changes
 *
 *
 */
package com.enterprisedt.net.ftp.internal;

import java.util.Locale;

import com.enterprisedt.net.ftp.DirectoryEmptyStrings;
import com.enterprisedt.net.ftp.FTPClient;
import com.enterprisedt.net.ftp.FTPConnectMode;
import com.enterprisedt.net.ftp.FTPControlSocket;
import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.FileNotFoundStrings;
import com.enterprisedt.net.ftp.TransferCompleteStrings;



/**
 *  Holds various parameters pertaining to the context of the connection. Used
 *  internally.
 *
 *  @author      Bruce Blackshaw
 *  @version     $Revision: 1.1 $
 */
public class ConnectionContext implements Cloneable {

    private String remoteHost;
    
    private String controlEncoding = FTPClient.DEFAULT_ENCODING;
    
    private int remotePort = FTPControlSocket.CONTROL_PORT;
    
    private int timeout = FTPClient.DEFAULT_TIMEOUT;
    
    private int transferNotifyInterval = FTPClient.DEFAULT_MONITOR_INTERVAL;
    
    /**
     * Size of transfer buffers
     */
    protected int transferBufferSize = FTPClient.DEFAULT_BUFFER_SIZE;
    
    private String username;
    
    private String password;
        
    private FTPTransferType transferType = FTPTransferType.BINARY;
    
    private FTPConnectMode connectMode = FTPConnectMode.ACTIVE;
        
    private Locale[] parserLocales = FTPClient.DEFAULT_LISTING_LOCALES;
    
    private int lowPort = -1;
    
    private int highPort = -1;
    
    /**
     * Use strict return codes if true
     */
    private boolean strictReturnCodes = false;
    
    /**
     * If true, uses the original host IP if an internal IP address
     * is returned by the server in PASV mode
     */
    private boolean autoPassiveIPSubstitution = true;
    
    /**
     * Delete partial files on transfer failure?
     */
    private boolean deleteOnFailure = true;
    
    /**
     * IP address to force to use in active mode
     */
    private String activeIP = null;
    
    /**
     * If true, filetypes are autodetected and transfer mode changed to binary/ASCII as 
     * required
     */
    private boolean detectContentType = false;
    
    /**
     * Listen to all interfaces in active mode
     */
    private boolean listenOnAllInterfaces = true;
    
    /** 
     * No explicit login required after connect
     */
    private boolean autoLogin = true;
    
    /**
     * Matcher for directory empty
     */
    private DirectoryEmptyStrings dirEmptyStrings = new DirectoryEmptyStrings();
    
    /**
     * Matcher for transfer complete
     */
    private TransferCompleteStrings transferCompleteStrings = new TransferCompleteStrings();
    
    /**
     * Matcher for permission denied
     */
    private FileNotFoundStrings fileNotFoundStrings = new FileNotFoundStrings();

    
    public ConnectionContext() {}
    
    public Object clone() {
        // no mutable fields so just grab a copy
        try {
            return super.clone();
        } catch (CloneNotSupportedException ignore) {
        }
        return null;
    }
    
    
    /**
     * Determine if auto login is switched on
     * 
     * @return true if auto login
     */
    public boolean isAutoLogin() {
        return autoLogin;
    }


    /**
     * Set the autoLogin flag
     * 
     * @param autoLogin   true if logging in automatically
     */
    public void setAutoLogin(boolean autoLogin) {
        this.autoLogin = autoLogin;
    }

    /**
     * Set autodetect of filetypes on or off. If on, the transfer mode is
     * switched from ASCII to binary and vice versa depending on the extension
     * of the file. After the transfer, the mode is always returned to what it
     * was before the transfer was performed. The default is off.
     * 
     * If the filetype is unknown, the transfer mode is unchanged
     * 
     * @param detectContentType    true if detecting transfer mode, false if not
     */
    public synchronized void setDetectContentType(boolean detectContentType) {
        this.detectContentType = detectContentType;
    }
    
    /**
     * Get the detect content type flag
     * 
     * @return true if we are detecting binary and ASCII transfers from the file type
     */
    public synchronized boolean getDetectContentType() {
        return detectContentType;
    }
    
    /**
     * We can force PORT to send a fixed IP address, which can be useful with certain
     * NAT configurations. 
     * 
     * @param activeIP     IP address to force, in 192.168.1.0 form or in IPV6 form, e.g.
     *                            1080::8:800:200C:417A
     */
    public synchronized void setActiveIPAddress(String activeIP) {
        
        this.activeIP = activeIP;
    }
    
    /**
     * The active IP address being used, or null if not used
     * @return IP address as a string or null
     */
    public synchronized String getActiveIPAddress() {
        return activeIP;
    }
    
    /**
     * Force a certain range of ports to be used in active mode. This is
     * generally so that a port range can be configured in a firewall. Note
     * that if lowest == highest, a single port will be used. This works well
     * for uploads, but downloads generally require multiple ports, as most
     * servers fail to create a connection repeatedly for the same port.
     * 
     * @param lowest     Lower limit of range.
     * @param highest    Upper limit of range.
     */
    public synchronized void setActivePortRange(int lowest, int highest) {
        this.lowPort = lowest;
        this.highPort = highest;
    }
    
    /**
     * Get the lower limit of the port range for active mode.
     * 
     * @return lower limit, or -1 if not set
     */
    public synchronized int getActiveLowPort() {
        return lowPort;
    }

    /**
     * Get the upper limit of the port range for active mode.
     * 
     * @return upper limit, or -1 if not set
     */
    public synchronized int getActiveHighPort() {
        return highPort;
    }
    
    /**
     * Set strict checking of FTP return codes. If strict 
     * checking is on (the default) code must exactly match the expected 
     * code. If strict checking is off, only the first digit must match.

⌨️ 快捷键说明

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