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

📄 ftpserver.java

📁 一个利用Java语言实现的ftp程序
💻 JAVA
字号:
/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included with this distribution in
 * the LICENSE file.
 */
package server.ftp;

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

import server.BaseServer;

/**
 * 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";
        
    // configuration object
    private FtpConfig mConfig;
    
    // pasv server socket
    private ServerSocket mPasvSocket;
    
    //////////////////////////////////////////////
    /**
     * Constructor.
     * @param configFile this ftp server configuration file. 
     */
    public FtpServer(File configFile) throws Exception {
        mConfig = new FtpConfig(configFile);
    }
    
    /**
     * 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);
        new Thread(ftpCon).start();
    }
    
    /**
     * Stop all currently executing threads.
     */
    public void dispose() {
        if (mConfig != null) {
            mConfig.dispose();
            mConfig = null;
        }
    } 
    
    /**
     * Get the configuration object.
     */
    public FtpConfig getConfig() {
        return mConfig;
    }
        
    
    /////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////
    /**
     * Command line ftp server starting point.
     */
/*    public static void main(String args[]) {
        
        // input argument check
        if(args.length != 1) {
            System.err.println("Usage: java server.ftp.FtpServer <config file>");
            System.exit(1);
        }
        
        try {
            BaseServer server = new FtpServer(new File(args[0]));
            final ServerEngine engine = new ServerEngine(server);
            
//            // add shutdown hook - since JDK1.3
//            Runnable shutdownHook = new Runnable() {
//                public void run() {
//                    System.out.println("Stopping server...");
//                    engine.stopServer();
//                }    
//            };
//            Runtime.getRuntime().addShutdownHook(new Thread(shutdownHook));
            engine.startServer();
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }    
    }
*/    
}

⌨️ 快捷键说明

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