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

📄 ftpeventhandler.java

📁 JAVA FTP客户端经典
💻 JAVA
字号:
/* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */package net.sf.jftp.event;import java.lang.reflect.*;import java.util.ArrayList;import java.util.Hashtable;import java.util.StringTokenizer;import java.util.Vector;import net.sf.jftp.net.FtpClient;public class FtpEventHandler implements EventHandler{    private FtpClient client;    private static ArrayList commands = null;    private Hashtable methods = new Hashtable();    static {        commands = new ArrayList();        commands.add("account");        commands.add("append");        commands.add("ascii");        commands.add("bell");        commands.add("bye");        commands.add("cd");        commands.add("cdup");        commands.add("chmod");        commands.add("close");        commands.add("cr"); // unsupported        commands.add("delete");        commands.add("dir");        commands.add("disconnect");        commands.add("form"); // unsupported        commands.add("get");        commands.add("glob"); // unsupported        commands.add("hash");        commands.add("idle");        commands.add("image");        commands.add("lcd");        commands.add("mdelete");        commands.add("mdir");        commands.add("mget");        commands.add("mkdir");        commands.add("mls");        commands.add("mode");        commands.add("modtime");        commands.add("mput");        commands.add("newer");        commands.add("nlist");        commands.add("open");        commands.add("passive");        commands.add("put");        commands.add("pwd");        commands.add("quote");        commands.add("recv");        commands.add("reget");        commands.add("rstatus");        commands.add("rhelp");        commands.add("rename");        commands.add("reset");        commands.add("restart");        commands.add("rmdir");        commands.add("runique");        commands.add("send");        commands.add("sendport");        commands.add("site");        commands.add("size");        commands.add("status");        commands.add("struct");        commands.add("system");        commands.add("sunique");        commands.add("type");        commands.add("user");    }        public FtpEventHandler()    {        this.client = new FtpClient();        Method[] m = this.getClass().getDeclaredMethods();        String methodName = null;        for (int i = 0; i < m.length; i++) {            methodName = m[i].getName();            if (commands.contains(methodName))                methods.put(methodName, m[i]);        }    }        public void open(Vector args)    {        System.out.println("***open");        client.login((String)args.elementAt(1));    }        public void disconnect(Vector args)    {        System.out.println("***disconnect");        client.disconnect();    }    public void cd(Vector args)    {        System.out.println("***cd");        client.cd((String)args.elementAt(1));    }    public void pwd(Vector args)    {        System.out.println("***pwd");        String directory = client.pwd();    }    public void get(Vector args)    {        System.out.println("***get");        client.get((String)args.elementAt(1));    }    public void put(Vector args)    {        System.out.println("***put");        client.put((String)args.elementAt(1));    }    public void quit(Vector args)    {        disconnect(args);    }    public boolean handle(Event e)    {        System.out.println(e.eventCode());        System.out.println(((FtpEvent)e).eventMsg());        StringTokenizer st = new StringTokenizer( ((FtpEvent)e).eventMsg() );        Vector list = new Vector();        while (st.hasMoreTokens())        {            list.addElement(st.nextToken());        }        if (list.size() != 0)        {            String command = (String)list.elementAt(0);            Method o = (Method)methods.get(command.toLowerCase());            if (o != null)            {                 try {                     o.invoke(this, new Object[] { list });                  } catch (Exception ex) {}            }        }        return true;    }}

⌨️ 快捷键说明

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