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

📄 sftphostchooser.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.gui;import net.sf.jftp.*;import net.sf.jftp.config.*;import net.sf.jftp.gui.framework.*;import net.sf.jftp.net.*;import net.sf.jftp.util.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.net.*;import javax.swing.*;public class SftpHostChooser extends HFrame implements ActionListener,                                                       WindowListener{    public static HTextField host = new HTextField("Host:", "localhost");    public static HTextField user = new HTextField("Username:", "guest");    public static HTextField port = new HTextField("Port:", "22");    public static HPasswordField pass = new HPasswordField("Password:",                                                           "nopasswd");    private HPanel okP = new HPanel();    private HButton ok = new HButton("Connect");    private ComponentListener listener = null;    private boolean useLocal = false;    public SftpHostChooser(ComponentListener l, boolean local)    {        listener = l;        useLocal = local;        init();    }    public SftpHostChooser(ComponentListener l)    {        listener = l;        init();    }    public SftpHostChooser()    {        init();    }    public void init()    {        setSize(500, 200);        setLocation(100, 150);        setTitle("Sftp Connection...");        setBackground(okP.getBackground());        getContentPane().setLayout(new GridLayout(3, 2));        //***MY CHANGES        try        {            File f = new File(Settings.appHomeDir);            f.mkdir();            File f1 = new File(Settings.login);            f1.createNewFile();            File f2 = new File(Settings.login_def_sftp);            f2.createNewFile();            File f3 = new File(Settings.ls_out);            f3.createNewFile();            File f4 = new File(Settings.sortls_out);            f4.createNewFile();            File f5 = new File(Settings.sortsize_out);            f5.createNewFile();            File f6 = new File(Settings.permissions_out);            f6.createNewFile();        }        catch(IOException ex)        {            ex.printStackTrace();        }        LoadSet l = new LoadSet();        String[] login = l.loadSet(Settings.login_def_sftp);        if(login[0] != null && login.length > 1)        {            host.setText(login[0]);            user.setText(login[1]);        }        /*        else {                host.setText("localhost");                user.setText("guest");        }        */        if(Settings.getStorePasswords())        {            if(login != null && login.length > 2 && login[2] != null)            {                pass.setText(login[2]);            }        }        else        {            pass.setText("");        }        //***end of my changes (for this section)        getContentPane().add(host);        getContentPane().add(port);        getContentPane().add(user);        getContentPane().add(pass);        getContentPane().add(new JLabel(""));        getContentPane().add(okP);        okP.add(ok);        ok.addActionListener(this);        setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);        pass.text.addActionListener(this);        setModal(false);        setVisible(false);        addWindowListener(this);    }    public void update()    {        setVisible(true);        toFront();        host.requestFocus();    }    public void actionPerformed(ActionEvent e)    {        if((e.getSource() == ok) || (e.getSource() == pass.text))        {            // Switch windows            //this.setVisible(false);            //this.setModal(false);            //JFtp.mainFrame.setVisible(true);            //JFtp.mainFrame.toFront();            setCursor(new Cursor(Cursor.WAIT_CURSOR));            SftpConnection con = null;            String htmp = host.getText().trim();            String utmp = user.getText().trim();            String ptmp = pass.getText();            //***port number: to be initialized in a future version?             int potmp = 22;            try            {                potmp = Integer.parseInt(port.getText());            }            catch(Exception ex)            {                Log.debug("Error: Not a number!");            }            String potmpString = new String("" + potmp);            try            {                boolean status;                SaveSet s = new SaveSet(Settings.login_def_sftp, htmp, utmp,                                        ptmp, potmpString, "null", "null");                status = StartConnection.startCon("SFTP", htmp, utmp, ptmp,                                                  potmp, "", useLocal);                /*                con = new SftpConnection(htmp);                //con.setLocalPath(JFtp.localDir.getCon().getPWD());                //con.addConnectionListener((ConnectionListener) JFtp.localDir);                //con.addConnectionListener((ConnectionListener) JFtp.remoteDir);                //JFtp.statusP.jftp.addConnection(htmp, con);                if(con.login(utmp,ptmp))                {                   if(useLocal) JFtp.statusP.jftp.addLocalConnection(htmp, con);                   else JFtp.statusP.jftp.addConnection(htmp, con);                       //JFtp.remoteDir.setCon(con);                       if(con.chdir(con.getPWD()) || con.chdir("/"));                }*/            }            catch(Exception ex)            {                Log.debug("Could not create SftpConnection, does this distribution come with jcifs?");            }            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));            this.dispose();            JFtp.mainFrame.setVisible(true);            JFtp.mainFrame.toFront();            if(listener != null)            {                listener.componentResized(new ComponentEvent(this, 0));            }        }    }    public void windowClosing(WindowEvent e)    {        //System.exit(0);        this.dispose();    }    public void windowClosed(WindowEvent e)    {    }    public void windowActivated(WindowEvent e)    {    }    public void windowDeactivated(WindowEvent e)    {    }    public void windowIconified(WindowEvent e)    {    }    public void windowDeiconified(WindowEvent e)    {    }    public void windowOpened(WindowEvent e)    {    }    public Insets getInsets()    {        Insets std = super.getInsets();        return new Insets(std.top + 15, std.left + 15, std.bottom + 15,                          std.right + 15);    }    public void pause(int time)    {        try        {            Thread.sleep(time);        }        catch(Exception ex)        {        }    }}

⌨️ 快捷键说明

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