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

📄 ftpserver.java

📁 Ftp服务1.0
💻 JAVA
字号:
package ranab.server.ftp;

import java.io.File;
import java.net.Socket;
import java.net.InetAddress;

import ranab.util.ThreadPool;
import ranab.server.BaseServer;
import ranab.server.ServerEngine;

/**
 * This is ftp server starting point. For each request it
 * instantiates a new <code>BaseFtpConnection</code> object.
 * 
 * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
 */
public
class FtpServer extends BaseServer {                             
    
    // server name
    public final static String NAME = "FTP";
    
    // thread pool
    private ThreadPool mThreadPool;
    
    // configuration object
    private FtpConfig mConfig;
    
    //////////////////////////////////////////////
    /**
     * Constructor.
     * @param configFile this ftp server configuration file. 
     */
    public FtpServer(File configFile) throws Exception {
        mConfig = new FtpConfig(configFile);
        mThreadPool = new ThreadPool(mConfig.getThreadCount());
        mThreadPool.start();
    }
    
    /**
     * Get server port.
     */
    public int getServerPort() {
        return mConfig.getServerPort();
    }
     
    /**
     * Get server bind address.
     */
    public InetAddress getServerAddress() {
        return mConfig.getServerAddress();
    }
     
    /**
     * Get server name.
     */
    public String getServerName() {
        return NAME;
    }
     
    /**
     * Serves threaded request. 
     */
    public void serveRequest(Socket soc) {
        BaseFtpConnection ftpCon = new FtpConnection(mConfig, soc);
        mThreadPool.add(ftpCon);
    }
    
    /**
     * Stop all currently executing threads.
     */
    public void dispose() {
        if (mThreadPool != null) {
            mThreadPool.dispose();
            mThreadPool = null;
        }
        if (mConfig != null) {
            mConfig.dispose();
            mConfig = null;
        }
    } 
    
    /**
     * Get the configuration object.
     */
    public FtpConfig getConfig() {
        return mConfig;
    }
     
    /**
     * Get max server connections - returns the thread count.
     */
    public int getMaxServerConnection() {
       return mConfig.getThreadCount();
    }
        
    
    /////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////
    /**
     * Command line ftp server starting point.
     */
    public static void main(String args[]) {
    
        try {
            if(args.length != 1) {
                System.err.println("Usage: java ranab.server.ftp.FtpServer <config file>");
                System.exit(1);
            }
            BaseServer server = new FtpServer(new File(args[0]));
            ServerEngine engine = new ServerEngine(server);
            engine.startServer();
        } catch (Exception ex) {
            ex.printStackTrace();
        }    
    }
}

⌨️ 快捷键说明

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