remotedir.java
来自「java ftp 操作代码,程序可以直接运行」· Java 代码 · 共 1,646 行 · 第 1/4 页
JAVA
1,646 行
{ ret = c.type(FtpConnection.L8); } if(!ret) { c.type(FtpConnection.ASCII); Log.debug("Warning: type should be \"I\" if you want to transfer binary files!"); } Log.debug("Type is now " + c.getTypeNow()); } else if(e.getActionCommand().equals("que")) /*&& (!JFtp.uiBlocked))*/ { if(!(con instanceof FtpConnection)) { Log.debug("Queue supported only for FTP"); return; } Object[] o = jl.getSelectedValues(); DirEntry[] tmp = new DirEntry[Array.getLength(o)]; for(int i = 0; i < Array.getLength(o); i++) { tmp[i] = (DirEntry) o[i]; JFtp.dQueue.addFtp(tmp[i].toString()); } } else if(e.getSource() == props) { JFtp.statusP.jftp.clearLog(); int x = currentPopup.getPermission(); String tmp; if(x == FtpConnection.R) { tmp = "read only"; } else if(x == FtpConnection.W) { tmp = "read/write"; } else if(x == FtpConnection.DENIED) { tmp = "denied"; } else { tmp = "undefined"; } String msg = "File: " + currentPopup.toString() + "\n" + " Size: " + currentPopup.getFileSize() + " raw size: " + currentPopup.getRawSize() + "\n" + " Symlink: " + currentPopup.isLink() + "\n" + " Directory: " + currentPopup.isDirectory() + "\n" + " Permission: " + tmp + "\n"; Log.debug(msg); } else if(e.getSource() == sorter) { sortMode = (String) sorter.getSelectedItem(); if(sortMode.equals("Date")) { Settings.showDateNoSize = true; } else { Settings.showDateNoSize = false; } fresh(); } else if(e.getActionCommand().equals("cdUp")) { JFtp.remoteDir.getCon().chdir(".."); } else if(e.getActionCommand().equals("rn")) { Object[] target = jl.getSelectedValues(); if((target == null) || (target.length == 0)) { Log.debug("No file selected"); return; } else if(target.length > 1) { Log.debug("Too many files selected"); return; } String val = JOptionPane.showInternalInputDialog(this, "Choose a name..."); if(val != null) { if(!con.rename(target[0].toString(), val)) { Log.debug("Rename failed."); } else { Log.debug("Successfully renamed."); fresh(); } } } } /** * Initiate a tranfer with ui locking enabled */ public synchronized void blockedTransfer(int index) { tmpindex = index; Runnable r = new Runnable() { public void run() { boolean block = !Settings.getEnableMultiThreading(); if(!(con instanceof FtpConnection)) { block = true; } if(block) { lock(false); } transfer(tmpindex); if(block) { JFtp.localDir.fresh(); unlock(false); } } }; Thread t = new Thread(r); t.start(); } /** * Lock the gui. */ public void lock(boolean first) { JFtp.uiBlocked = true; jl.setEnabled(false); if(!first) { JFtp.localDir.lock(true); } Log.out("ui locked."); } /** * Unlock the gui. */ public void unlock(boolean first) { JFtp.uiBlocked = false; jl.setEnabled(true); if(!first) { JFtp.localDir.unlock(true); } Log.out("ui unlocked."); } /** * Do a hard UI refresh - do no longe call this directly, use * safeUpdate() instead if possible. */ public void fresh() { Log.out("fresh() called."); Cursor x = null; if(JFtp.mainFrame != null) { x = JFtp.mainFrame.getCursor(); JFtp.mainFrame.setCursor(Cursor.WAIT_CURSOR); } //TODO .debug("fresh()"); String i = ""; int idx = jl.getSelectedIndex(); if(idx >= 0) { Object o = jl.getSelectedValue(); if(o != null) { i = o.toString(); } } con.chdir(path); if((idx >= 0) && (idx < jl.getModel().getSize())) { if(jl.getModel().getElementAt(idx).toString().equals(i)) { jl.setSelectedIndex(idx); } else { jl.setSelectedIndex(0); } } update(); if((JFtp.mainFrame != null) && (x.getType() != Cursor.WAIT_CURSOR)) { JFtp.mainFrame.setCursor(Cursor.DEFAULT_CURSOR); } } /** * Called by FtpConnection, DownloadList is updated from here */ public void updateProgress(String file, String type, long bytes) { if((dList == null) || (dirEntry == null)) { return; } boolean flag = false; 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 = 0; if(JFtp.dList.sizeCache.containsKey(file)) { s = ((Long) JFtp.dList.sizeCache.get(file)).longValue(); } else { for(int i = 0; i < dirEntry.length; i++) { if(dirEntry[i] == null) { continue; } if(dirEntry[i].toString().equals(file)) { s = dirEntry[i].getRawSize(); JFtp.dList.sizeCache.put(file, new Long(s)); break; } } if(s <= 0) { File f = new File(JFtp.localDir.getPath() + file); if(f.exists()) { s = f.length(); } } } dList.updateList(file, type, bytes, s); } /** * Called by FtpConnection */ public void connectionInitialized(BasicConnection con) { if(con == null) { return; } 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) && !(con instanceof FilesystemConnection)) { try { sorter.removeItem("Date"); } catch(Exception ex) { } dateEnabled = false; return; } //Log.debug(">>> date gui init"); if((con instanceof FtpConnection) && (((FtpConnection) con).dateVector.size() > 0)) { if(!dateEnabled) { sorter.addItem("Date"); dateEnabled = true; UpdateDaemon.updateRemoteDirGUI(); } } else if((con instanceof FilesystemConnection) && (((FilesystemConnection) con).dateVector.size() > 0)) { if(!dateEnabled) { sorter.addItem("Date"); dateEnabled = true; UpdateDaemon.updateRemoteDirGUI(); } } else { if(dateEnabled) { try { sorter.removeItem("Date"); dateEnabled = false; Settings.showDateNoSize = false; UpdateDaemon.updateRemoteDirGUI(); } catch(Exception ex) { } } } } /** * Called by FtpConnection */ public void updateRemoteDirectory(BasicConnection c) { //TODO Log.debug("updateRemoteDirectory()"); if(con == null) { return; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?