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

📄 remotedir.java

📁 JAVA FTP客户端经典
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                ex.printStackTrace();            }        }	else if(e.getActionCommand().equals("type") && (!JFtp.uiBlocked))	{	 if(!(con instanceof FtpConnection))	 {	 	Log.debug("You can only set the transfer type for ftp connections.");	 	return;	}	 FtpConnection c = (FtpConnection) con;	 String t = c.getTypeNow();	 boolean ret = false;	 if(t.equals(FtpConnection.ASCII))	 {	 	ret = c.type(FtpConnection.BINARY);	 }	 else if(t.equals(FtpConnection.BINARY))	 {	 	ret = c.type(FtpConnection.EBCDIC);	 }	 if(t.equals(FtpConnection.EBCDIC) || (!ret && !t.equals(FtpConnection.L8)))	 {	 	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("open"))        {	    JFtp.safeDisconnect();	    HostChooser hc = new HostChooser();            hc.toFront();	    hc.setModal(true);            hc.update();        }*/    }    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();    }    public void lock(boolean first)    {    	JFtp.uiBlocked = true;	jl.setEnabled(false);	if(!first) JFtp.localDir.lock(true);    }    public void unlock(boolean first)    {    	JFtp.uiBlocked = false;	jl.setEnabled(true);	if(!first) JFtp.localDir.unlock(true);    }    public void fresh()    {      Cursor x = JFtp.mainFrame.getCursor();      if(JFtp.mainFrame != null) 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);	 if(JFtp.mainFrame != null && x.getType() != Cursor.WAIT_CURSOR) JFtp.mainFrame.setCursor(Cursor.DEFAULT_CURSOR);    }    /** this manages the selections */    public void valueChanged(ListSelectionEvent e)    {        if (e.getValueIsAdjusting() == false)        {	    							  //  ui refresh bugfix	    int index = jl.getSelectedIndex()-1;            if (index < 0 || dirEntry == null || dirEntry.length < index || dirEntry[index] == null)            {	    	return;            }            else            {                    String tgt=(String)jl.getSelectedValue().toString();		    //if (index < 0)                    //{                        //con.chdir(path+tgt);                    //}                    for (int i=0; i<dirEntry.length; i++)                    {                        dirEntry[i].setSelected(jl.isSelectedIndex(i+1));                    }            }        }    }    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(dummy.containsKey(file))	{		s = ((Long) dummy.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();		 dummy.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);    }    public void connectionInitialized(BasicConnection con) {}    public void connectionFailed(BasicConnection con, String reason)    {    	if(reason.equals(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();    }    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;	}	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);	//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])) System.out.println("mismatch");      }      for (int i = 0; i < cacheEntry.length; i++)      {        if (bFileSelected[i])	{		startTransfer(cacheEntry[i]);        }      }    } public void startTransfer(DirEntry entry) {  if(JFtp.remoteDir.getCon() instanceof FtpConnection)  {	int status = checkForExistingFile(entry);	if(status >= 0)	{			if(entry.getRawSize() < Settings.smallSize && !entry.isDirectory()) con.download(entry.file);			else con.handleDownload(path+entry.file);	} } else if(con instanceof FilesystemConnection)  {  	con.download(path+entry.file);	JFtp.localDir.actionPerformed(con, "");  }  else  {  	con.handleDownload(entry.file);	JFtp.localDir.actionPerformed(con, "");  }}    /** 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]);        }    }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;}public void actionFinished(BasicConnection c) {	JFtp.localDir.actionPerformed(c, "LOWFRESH");	        if(con instanceof FtpConnection)	{		if(con.hasUploaded) fresh();	}	else	{		fresh();	}}public void actionPerformed(Object target, String msg){	if(msg.equals(type))	{		gui(true);		//updateRemoteDirectory(con);	}	else if(msg.equals("FRESH")) fresh();}   String cutPath(String s)    {        int maxlabel = 64;        if(s.length() > maxlabel)        {            while(true)            {                s = StringUtils.cutAfter(s,'/');                if(s.length() < 16)                {                    StringBuffer sb = new StringBuffer(s);                    sb.insert(0,".../");                    return sb.toString();                }            }        }        return s;    }    public void showContentWindow(String url, DirEntry d)    {     try     {	 if(d.getRawSize() > 200000)	 {		Log.debug("File is too big - 200kb is the maximum, sorry.");		return;	}        con.download(url);	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 + -