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

📄 ftpframe.java

📁 ftp client with java
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * 10/01/2001 - 15:52:00 * * FtpGUI - Ftp client written in Java * Copyright (C) 2001 Kostadin Kirilov Kostadinov * k3co@hotmail.com * sourceforge.net * * This program 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 * 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package ftpgui;import java.awt.*;import java.io.*;import java.util.*;import java.net.*;import java.awt.event.*;import java.beans.*;import java.lang.reflect.*;import javax.swing.*;import javax.swing.event.*;import javax.swing.text.*;import javax.swing.plaf.*;import sun.net.ftp.*;import sun.net.*;/** * Title:        FtpGUI * Description: * Copyright:    Copyright (c) 2001 * Company: * @author Kostadin Kirilov Kostadinov * @version 1.0 */public class FtpFrame extends JFrame implements ActionListener, HyperlinkListener, TaskEventListener{    JPanel contentPane;    JMenuBar m_mnubarMainMenuBar;    JMenu m_mnuFile;    JMenuItem m_mnuFileExit;    JMenuItem m_mnuConnect;    JMenuItem m_mnuClose;    JMenu m_mnuHelp;    JMenuItem m_mnuHelpAbout;    JToolBar m_toolbarMainToolBar;    JButton m_btnOpen;    JButton m_btnUpload;    JButton m_btnAbout;    ImageIcon imgConnect;    ImageIcon imgSave;    ImageIcon imgHelp;    ImageIcon imgCDUP;    ImageIcon imgSearch;    BorderLayout borderLayoutOfFrame;    Workthread m_objWorkthread=new Workthread();    private boolean m_booIsStandalone=true;    /**Construct the frame*/    public FtpFrame()    {        initLogFile();        enableEvents(AWTEvent.WINDOW_EVENT_MASK);        try        {            jbInit();        }        catch(Exception e)        {            e.printStackTrace();        }    }    public void setStandalone(boolean booIsStandalone)    {        m_booIsStandalone=booIsStandalone;    }    public boolean isStandalone()    {        return m_booIsStandalone;    }    void initLogFile()    {        try        {            String strLogDir=System.getProperty("user.home")+                                File.separator+".FtpGUI";            File objDir=new File(strLogDir);            if(!(objDir.exists()))            {                objDir.mkdirs();            }            String strLogFile=strLogDir+File.separator+"FtpGUILogFile.log";            Logger.setLogFileName(strLogFile);            Logger.setLogingInFile(true);        }catch(Exception e)        {            e.printStackTrace();        }    }    /**Component initialization*/    private void jbInit() throws Exception    {        imgConnect = new ImageIcon(ftpgui.FtpFrame.class.getResource("openFile.gif"));        imgSave = new ImageIcon(ftpgui.FtpFrame.class.getResource("closeFile.gif"));        imgHelp = new ImageIcon(ftpgui.FtpFrame.class.getResource("help.gif"));        imgCDUP = new ImageIcon(ftpgui.FtpFrame.class.getResource("cdup.gif"));        imgSearch = new ImageIcon(ftpgui.FtpFrame.class.getResource("search.gif"));        m_btnAbout = (JButton)Beans.instantiate(getClass().getClassLoader(),JButton.class.getName());        m_btnUpload = (JButton)Beans.instantiate(getClass().getClassLoader(),JButton.class.getName());        m_btnOpen = (JButton)Beans.instantiate(getClass().getClassLoader(),JButton.class.getName());        m_toolbarMainToolBar = (JToolBar)Beans.instantiate(getClass().getClassLoader(),JToolBar.class.getName());        m_mnuHelpAbout = (JMenuItem)Beans.instantiate(getClass().getClassLoader(),JMenuItem.class.getName());        m_mnuHelp = (JMenu)Beans.instantiate(getClass().getClassLoader(),JMenu.class.getName());        m_mnuFileExit = (JMenuItem)Beans.instantiate(getClass().getClassLoader(),JMenuItem.class.getName());        m_mnuFile = (JMenu)Beans.instantiate(getClass().getClassLoader(),JMenu.class.getName());        m_mnubarMainMenuBar = (JMenuBar)Beans.instantiate(getClass().getClassLoader(),JMenuBar.class.getName());        m_mnuConnect = (JMenuItem)Beans.instantiate(getClass().getClassLoader(),JMenuItem.class.getName());        m_mnuClose = (JMenuItem)Beans.instantiate(getClass().getClassLoader(),JMenuItem.class.getName());        borderLayoutOfFrame = (BorderLayout)Beans.instantiate(getClass().getClassLoader(),BorderLayout.class.getName());        //setIconImage(Toolkit.getDefaultToolkit().createImage(FtpFrame.class.getResource("[Your Icon]")));        contentPane = (JPanel) this.getContentPane();        btnCDUP = (JButton) Beans.instantiate(getClass().getClassLoader(), JButton.class.getName());        btnSearch = (JButton) Beans.instantiate(getClass().getClassLoader(), JButton.class.getName());        btnCD = (JButton) Beans.instantiate(getClass().getClassLoader(), JButton.class.getName());        jPanel1 = (JPanel) Beans.instantiate(getClass().getClassLoader(), JPanel.class.getName());        gridLayout1 = (GridLayout) Beans.instantiate(getClass().getClassLoader(), GridLayout.class.getName());        statusBar = (JTextField) Beans.instantiate(getClass().getClassLoader(), JTextField.class.getName());        progressBar = (JProgressBar) Beans.instantiate(getClass().getClassLoader(), JProgressBar.class.getName());        progressBar.setStringPainted(true);        progressBar.setBorderPainted(true);        contentPane.setLayout(borderLayoutOfFrame);        this.setSize(new Dimension(500, 400));        this.setTitle("FtpGUI");        m_mnuFile.setText("File");        m_mnuFileExit.setText("Exit");        m_mnuFileExit.addActionListener(this);        m_mnuConnect.addActionListener(this);        m_mnuClose.addActionListener(this);        m_mnuConnect.setText("Open");        m_mnuClose.setText("Close");        m_mnuHelp.setText("Help");        m_mnuHelpAbout.setText("About");        m_mnuHelpAbout.addActionListener(this);        m_btnOpen.setIcon(imgConnect);        m_btnOpen.setToolTipText("Connect to the FTP Server");        m_btnUpload.setIcon(imgSave);        m_btnUpload.setToolTipText("Close File");        m_btnAbout.setIcon(imgHelp);        m_btnAbout.addActionListener(this);        m_btnAbout.setToolTipText("Help");        m_btnOpen.addActionListener(this);        m_btnUpload.addActionListener(this);        btnCDUP.setIcon(imgCDUP);        btnCDUP.addActionListener(this);        btnSearch.setIcon(imgSearch);        btnSearch.addActionListener(this);        btnCD.setText("CD");        btnCD.addActionListener(this);        jPanel1.setLayout(gridLayout1);        jPanel1.setMinimumSize(new Dimension(0, 100));        jPanel1.setPreferredSize(new Dimension(0, 20));        statusBar.setBackground(new Color(236, 197, 255));        statusBar.setEditable(false);        progressBar.setBackground(new Color(190, 190, 255));        progressBar.setForeground(new Color(236, 184, 0));        m_toolbarMainToolBar.add(m_btnOpen);        m_toolbarMainToolBar.add(m_btnUpload);        m_toolbarMainToolBar.add(m_btnAbout);        m_toolbarMainToolBar.add(btnCDUP, null);        m_toolbarMainToolBar.add(btnSearch, null);        m_toolbarMainToolBar.add(btnCD, null);        m_mnuFile.add(m_mnuConnect);        m_mnuFile.add(m_mnuClose);        m_mnuFile.add(m_mnuFileExit);        m_mnuHelp.add(m_mnuHelpAbout);        m_mnubarMainMenuBar.add(m_mnuFile);        m_mnubarMainMenuBar.add(m_mnuHelp);        this.setJMenuBar(m_mnubarMainMenuBar);        contentPane.add(m_toolbarMainToolBar, BorderLayout.NORTH);        //Create the HTML viewing pane.        htmlPane = new JTextPane();        htmlPane.setEditable(false);        htmlPane.addHyperlinkListener(this);        JScrollPane htmlView=new JScrollPane(htmlPane);        contentPane.add(htmlView, BorderLayout.CENTER);        contentPane.add(jPanel1, BorderLayout.SOUTH);        jPanel1.add(statusBar, null);        jPanel1.add(progressBar, null);    }    JTextPane htmlPane=null;    private ConnectPanel m_objConnectPanel=new ConnectPanel();    public void showOpenServerDialog()    {   		Object l_objects[] = new Object[1];		l_objects[0] = m_objConnectPanel;        String l_options[] = {            "Conect", "Cancel"        };        if(JOptionPane.showOptionDialog(this, ((Object) (l_objects)),        	 "Connection Options", -1, 3, null, l_options, l_options[0]) == 0)        {        	Logger.log("Connect");            statusBar.setText("Connecting");            //Call connect() in separeted thread            try            {                Class arrClass[]=new Class[0];                Method objMethod=this.getClass().getMethod("connect",arrClass);                m_objTask=new Task(objMethod ,this,null);                String strID=m_objWorkthread.addTask(m_objTask);                //System.out.println("Added task strID="+strID);                //m_objWorkthread.startWork();                starTiming();            }catch(Exception e){e.printStackTrace();}        }    }    Task m_objTask=null;    javax.swing.Timer timer = null;    private void starTiming()    {        if(timer!=null)        {            timer.stop();            timer=null;        }        progressBar.setMaximum(100);        progressBar.setMinimum(0);        int ONE_SECOND=1000;        timer = new javax.swing.Timer(ONE_SECOND, new ActionListener()        {            public void actionPerformed(ActionEvent evt)            {                int i=progressBar.getValue()+1;                //System.out.println("progressBar.getValue()+1="+i);                progressBar.setValue(i);//task.getCurrent());                if((progressBar.getValue()>=progressBar.getMaximum()) ||                    m_objTask.m_booDone)                {                    progressBar.setValue(progressBar.getMinimum());                    timer.stop();                }            }        });        timer.start();        System.out.println("Timer started");    }    FtpClient m_objFtpClient=null;    public void connect()    {        setWaitCursor();        String strServerIP=m_objConnectPanel.m_txtServerIP.getText();        String strServerPort=m_objConnectPanel.m_txtServerPort.getText();        String strUserName=m_objConnectPanel.m_txtUserName.getText();        String strPassword=m_objConnectPanel.m_txtPassword.getText();        try        {            int iPort=Integer.parseInt(strServerPort);            Logger.log("Connecting");            if(m_objFtpClient!=null)                m_objFtpClient.closeServer();            m_objFtpClient=new FtpClient(strServerIP,iPort);            Logger.log("Connected");        }catch(Exception e)        {            e.printStackTrace();            showError("Couldn't connect to Server : "+strServerIP+" on port : "+strServerPort,                "Couldn't connect to Server");        }        try        {            Logger.log("Loging");            m_objFtpClient.login(strUserName,strPassword);            Logger.log("Retrieving content of current directory");            lsCurrentDir();        }        catch(FtpLoginException e)        {            e.printStackTrace();            showError("Couldn't login "+"to Server : "+strServerIP+                " on port : "+strServerPort+                " with user name : "+strUserName+                " and password "+strPassword+                "\nPerhaps you have to check user name and password.",                "Couldn't login ");        }        catch(IOException e)        {            e.printStackTrace();            showError("Couldn't login "+"to Server : "+strServerIP+                " on port : "+strServerPort+

⌨️ 快捷键说明

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