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

📄 remotedir.java

📁 一个JAVA做的FTP软件,带源码的,可以很好的进行二次开发,,并带有详细说明文件的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }		setDate();	        Log.out("remote connection initialized");    }    /**    * Called by FtpConnection    */    public void connectionFailed(BasicConnection con, String reason)    {        Log.out("remote connection failed");        if((Integer.parseInt(reason) == FtpConnection.OFFLINE) &&               Settings.reconnect)        {            return;        }        //this.con = con;        HFrame h = new HFrame();        h.getContentPane().setLayout(new BorderLayout(10, 10));        h.setTitle("Connection failed!");        h.setLocation(150, 200);        JTextArea text = new JTextArea();        h.getContentPane().add("Center", text);        text.setText(" ---------------- Output -----------------\n" +                     JFtp.log.getText());        JFtp.log.setText("");        text.setEditable(false);        h.pack();        h.show();    }        private void setDate()    {    	if(!(con instanceof FtpConnection)) 	{		try		{			sorter.removeItem("Date");		}		catch(Exception ex)		{		}				dateEnabled = false;		return;	}	    	    //Log.debug(">>> date gui init");	     	    if(((FtpConnection)con).dateVector.size() > 0)	    {	    	if(!dateEnabled)		{			sorter.addItem("Date");				dateEnabled = true;			UpdateDaemon.updateRemoteDirGUI();		}	    }	    else	    {	    	if(dateEnabled)		{	    		sorter.removeItem("Date");   			dateEnabled = false;			Settings.showDateNoSize = false;			UpdateDaemon.updateRemoteDirGUI();		}	    }    }    /**    * Called by FtpConnection    */    public void updateRemoteDirectory(BasicConnection c)    {        //TODO Log.debug("updateRemoteDirectory()");        if(con == null)        {            return;        }        if((c != con) && !c.hasUploaded && con instanceof FtpConnection)        {            //System.out.println("Skipping connection: " + con.getCachedPWD() + " : " + JFtp.remoteDir.path);            return;        }        Log.out("update remote directory");	setDate();        if(con instanceof FtpConnection)        {            path = ((FtpConnection) con).getCachedPWD();        }        else if(con instanceof SmbConnection && !path.startsWith("smb://"))        {            path = c.getPWD();        }        else        {            path = con.getPWD();        }        //System.out.println("path: "+path +":"+ con +":" +con.getPWD() +":"+c+":" +c.getPWD());        if((c != null) && (c instanceof FtpConnection))        {            FtpConnection con = (FtpConnection) c;            String tmp = con.getCachedPWD();            SaveSet s = new SaveSet(Settings.login_def, con.getHost(),                                    con.getUsername(), con.getPassword(),                                    Integer.toString(con.getPort()), tmp,                                    con.getLocalPath());        }        else if((c != null) && (c instanceof FilesystemConnection))        {            JFtp.localDir.getCon().setLocalPath(path);        }        //TODO .debug("before gui()");        //Log.debug(c.toString());        pathChanged = true;        gui(false);        UpdateDaemon.updateLog();        //JFtp.statusP.jftp.ensureLogging();        //TODO .debug("after gui()");    }    /**    * Transfers all selected files     */    public synchronized void transfer()    {        boolean[] bFileSelected = new boolean[dirEntry.length + 1];        DirEntry[] cacheEntry = new DirEntry[dirEntry.length];        System.arraycopy(dirEntry, 0, cacheEntry, 0, cacheEntry.length);        for(int i = 0; i < dirEntry.length; i++)        {            bFileSelected[i] = cacheEntry[i].selected;            if(!cacheEntry[i].equals(dirEntry[i]))            {                Log.out("mismatch");            }        }        for(int i = 0; i < cacheEntry.length; i++)        {            if(bFileSelected[i])            {                startTransfer(cacheEntry[i]);            }        }    }    /**    * Start a file transfer.    * Depending on the local and remote connection types some things like    * local working directory have to be set, resuming may have to be checked etc.    * As with ftp to ftp transfers the action used to download a file might actually be    * an upload.    *    * WARNING: If you do anything here, please check LocalDir.startTransfer(), too!    */    public void startTransfer(DirEntry entry)    {        if(con instanceof FtpConnection &&               JFtp.localDir.getCon() instanceof FtpConnection)        {            if(entry.isDirectory())            {                Log.debug("Directory transfer between remote connections is not supported yet!");                return;            }            Log.out("direct ftp transfer started (download)");            ((FtpConnection) JFtp.localDir.getCon()).upload(entry.file,                                                            ((FtpConnection) JFtp.remoteDir.getCon()).getDownloadInputStream(path +                                                                                                                             entry.file));        }        else if(con instanceof FtpConnection &&                    JFtp.localDir.getCon() instanceof FilesystemConnection)        {            // local: file, remote: ftp            int status = checkForExistingFile(entry);            if(status >= 0)            {                //--------------------------------------------                // dirty bugfix for sizes that would be                // messed up otherwise                /*                boolean flag = false;                String file = entry.file;                if(file.endsWith("/") && (file.length() > 1))                {                    flag = true;                    file = file.substring(0, file.lastIndexOf("/"));                }                file = file.substring(file.lastIndexOf("/") + 1);                if(flag)                {                    file = file + "/";                } */                long s = entry.getRawSize();                JFtp.dList.sizeCache.put(entry.file, new Long(s));                // ---------------------------------                if((entry.getRawSize() < Settings.smallSize) &&                       !entry.isDirectory())                {                    con.download(entry.file);                }                else                {                    con.handleDownload(path + entry.file);                }            }        }        else if(con instanceof FilesystemConnection &&                    JFtp.localDir.getCon() instanceof FtpConnection)        {            try            {                File f = new File(path + entry.file);                FileInputStream in = new FileInputStream(f);                JFtp.localDir.getCon().setLocalPath(path);                Log.debug(JFtp.localDir.getCon().getPWD());                ((FtpConnection) JFtp.localDir.getCon()).upload(entry.file, in);            }            catch(FileNotFoundException ex)            {                Log.debug("Error: File not found: " + path + entry.file);            }        }        else if(con instanceof FilesystemConnection &&                    JFtp.localDir.getCon() instanceof FilesystemConnection)        {            con.download(path + entry.file);            JFtp.localDir.actionPerformed(con, "");        }        else if(JFtp.localDir.getCon() instanceof FilesystemConnection)        {            // local: file, remote: smb, sftp, nfs            con.handleDownload(entry.file);            JFtp.localDir.actionPerformed(con, "");        }        else        {            if(entry.isDirectory())            {                Log.debug("Directory transfer between remote connections is not supported yet!");                return;            }            Log.out("direct transfer started (download)");            JFtp.localDir.getCon().upload(entry.file,                                          JFtp.remoteDir.getCon()                                                        .getDownloadInputStream(path +                                                                                entry.file));            JFtp.localDir.actionPerformed(con, "FRESH");        }    }    /**    * Transfers single file, or all selected files if index is -1     */    public void transfer(int i)    {        if(i == -2)        {            transfer();            return;        }        else if(dirEntry[i].selected)        {            startTransfer(dirEntry[i]);        }    }    /**    * Ask for resuming or overwrite if a local file does already exist for a download    */    private int checkForExistingFile(DirEntry dirEntry)    {        File f = new File(JFtp.localDir.getPath() + dirEntry.file);        if(f.exists() && Settings.enableResuming && Settings.askToResume)        {            ResumeDialog r = new ResumeDialog(dirEntry); // ResumeDialog handels the rest            return -1;        }        return 1;    }    /**    * Called by FtpConnection    */    public void actionFinished(BasicConnection c)    {        JFtp.localDir.actionPerformed(c, "LOWFRESH");        if(c instanceof FtpConnection)        {            if(((FtpConnection) c).hasUploaded)            {                Log.out("actionFinished called by upload: " + c);                //fresh();                UpdateDaemon.updateRemoteDir();            }            Log.out("actionFinished called by download: " + c);        }        else        {            Log.out("actionFinished called by: " + c);            //fresh();            UpdateDaemon.updateRemoteDir();        }        //JFtp.statusP.jftp.ensureLogging();        UpdateDaemon.updateLog();    }    /**    * Called by FtpConnection    */    public void actionPerformed(Object target, String msg)    {        if(msg.equals(type))        {            UpdateDaemon.updateRemoteDirGUI();            //gui(true);            //updateRemoteDirectory(con);        }        else if(msg.equals("FRESH"))        {            UpdateDaemon.updateRemoteDir();            //fresh();        }        //Log.out("actionPerformed called.");        //JFtp.statusP.jftp.ensureLogging();        UpdateDaemon.updateLog();    }    /**    * Mime type handler for doubleclicks on files    */    public void showContentWindow(String url, DirEntry d)    {        try        {            if(d.getRawSize() > 200000)            {                Log.debug("File is too big - 200kb is the maximum, sorry.");                return;            }	    String path = JFtp.localDir.getPath();	    if(!path.endsWith("/")) path = path + "/";	                if(!new File(path+StringUtils.getFile(url)).exists())	    {	    	con.download(url);	    }	    else 	    {	    	Log.debug("\nRemote file must be downloaded to be viewed and\n"+			  " you already have a local copy present, pleasen rename it\n"+			  " and try again.");			 		return;	    }            File file = new File(JFtp.localDir.getPath() +                                 StringUtils.getFile(url));            if(!file.exists())            {                Log.debug("File not found: " + JFtp.localDir.getPath() +                          StringUtils.getFile(url));            }            HFrame f = new HFrame();            f.setTitle(url);            JEditorPane pane = new JEditorPane("file://" +                                               file.getAbsolutePath());            if(!pane.getEditorKit().getContentType().equals("text/html") &&                   !pane.getEditorKit().getContentType().equals("text/rtf"))            {                if(!pane.getEditorKit().getContentType().equals("text/plain"))                {                    Log.debug("Nothing to do with this filetype - use the buttons if you want to transfer files.");                    return;                }                pane.setEditable(false);            }            JScrollPane jsp = new JScrollPane(pane);            f.getContentPane().setLayout(new BorderLayout());            f.getContentPane().add("Center", jsp);            f.setModal(false);            f.setLocation(100, 100);            f.setSize(600, 400);            //f.pack();            f.show();            dList.fresh();            JFtp.localDir.getCon().removeFileOrDir(StringUtils.getFile(url));            JFtp.localDir.fresh();        }        catch(Exception ex)        {            Log.debug("File error: " + ex);        }    }    public void keyPressed(KeyEvent e)    {        if(e.getKeyCode() == KeyEvent.VK_ENTER)        {            Object o = jl.getSelectedValue();            if(o == null)            {                return;            }            String tmp = ((DirEntry) o).toString();            if(tmp.endsWith("/"))            {                con.chdir(tmp);            }            else            {                showContentWindow(path + tmp, (DirEntry) o);            }        }        else if(e.getKeyCode() == KeyEvent.VK_SPACE)        {            int x = ((DirPanel) JFtp.localDir).jl.getSelectedIndex();            if(x == -1)            {                x = 0;            }            ((DirPanel) JFtp.localDir).jl.grabFocus();            ((DirPanel) JFtp.localDir).jl.setSelectedIndex(x);        }    }    public void keyReleased(KeyEvent e)    {    }    public void keyTyped(KeyEvent e)    {    }}

⌨️ 快捷键说明

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