Revision: 18111
http://jedit.svn.sourceforge.net/jedit/?rev=18111&view=rev
Author: voituk
Date: 2010-06-18 21:03:22 +0000 (Fri, 18 Jun 2010)
Log Message:
-----------
- Re-ask for connection details if no key-file exists
- Fixed problem with authentication on some sFTP servers (promptKeyboardInteractive method impelented)
Modified Paths:
--------------
plugins/FTP/trunk/FTP.props
plugins/FTP/trunk/ftp/ConnectionInfo.java
plugins/FTP/trunk/ftp/ConnectionManager.java
plugins/FTP/trunk/ftp/FtpVFS.java
plugins/FTP/trunk/ftp/SFtpConnection.java
plugins/FTP/trunk/users-guide.xml
Modified: plugins/FTP/trunk/FTP.props
===================================================================
--- plugins/FTP/trunk/FTP.props 2010-06-18 19:21:38 UTC (rev 18110)
+++ plugins/FTP/trunk/FTP.props 2010-06-18 21:03:22 UTC (rev 18111)
@@ -3,7 +3,7 @@
plugin.ftp.FtpPlugin.name=FTP
plugin.ftp.FtpPlugin.author=Slava Pestov, Nicholas O'Leary, Vadim Voituk
-plugin.ftp.FtpPlugin.version=0.9.8
+plugin.ftp.FtpPlugin.version=0.9.8.2
plugin.ftp.FtpPlugin.dev.revision=$Rev$
plugin.ftp.FtpPlugin.docs=index.html
plugin.ftp.FtpPlugin.depend.0=jedit 04.03.04.00
Modified: plugins/FTP/trunk/ftp/ConnectionInfo.java
===================================================================
--- plugins/FTP/trunk/ftp/ConnectionInfo.java 2010-06-18 19:21:38 UTC (rev 18110)
+++ plugins/FTP/trunk/ftp/ConnectionInfo.java 2010-06-18 21:03:22 UTC (rev 18111)
@@ -14,8 +14,7 @@
public String privateKey;
// }}}
- public ConnectionInfo(boolean secure, String host, int port,
- String user, String password, String privateKey)
+ public ConnectionInfo(boolean secure, String host, int port,String user, String password, String privateKey)
{
this.secure = secure;
this.host = host;
@@ -45,8 +44,7 @@
public String toString()
{
- return (secure ? FtpVFS.SFTP_PROTOCOL : FtpVFS.FTP_PROTOCOL)
- + "://" + host + ":" + port;
+ return (secure ? FtpVFS.SFTP_PROTOCOL : FtpVFS.FTP_PROTOCOL) + "://" + host + ":" + port;
}
public int hashCode()
Modified: plugins/FTP/trunk/ftp/ConnectionManager.java
===================================================================
--- plugins/FTP/trunk/ftp/ConnectionManager.java 2010-06-18 19:21:38 UTC (rev 18110)
+++ plugins/FTP/trunk/ftp/ConnectionManager.java 2010-06-18 21:03:22 UTC (rev 18111)
@@ -29,6 +29,7 @@
import org.gjt.sp.jedit.GUIUtilities;
import org.gjt.sp.jedit.MiscUtilities;
import org.gjt.sp.jedit.jEdit;
+import org.gjt.sp.util.IOUtilities;
import org.gjt.sp.util.Log;
import com.jcraft.jsch.JSch;
@@ -46,7 +47,7 @@
protected static HashMap<String, ConnectionInfo> logins;
protected static HashMap<String, String> passwords;
protected static HashMap<String, String> passphrases;
- static int connectionTimeout = 120000;
+ static int connectionTimeout = 60000;
private static File passwordFile = null;
public static JSch client = null;
// }}}
@@ -59,8 +60,7 @@
passwordFile.delete();
passwordFile.createNewFile();
} catch(IOException e) {
- Log.log(Log.WARNING,ConnectionManager.class,
- "Unable to create password file:"+passwordFile);
+ Log.log(Log.WARNING,ConnectionManager.class, "Unable to create password file:"+passwordFile);
}
passwords.clear();
passphrases.clear();
@@ -93,8 +93,14 @@
} //}}}
+ /**
+ * @return null if no
+ */
public static String getStoredFtpKey(String host, String user) {
- return jEdit.getProperty("ftp.keys."+host+"."+user);
+ String s = jEdit.getProperty("ftp.keys."+host+"."+user);
+ if (s==null || s.length()<=0)
+ return null;
+ return new File(s).exists() ? s : null;
}
//{{{ loadPasswords() method
@@ -126,9 +132,7 @@
byte[] uncompressed = comp.uncompress(buffer,0,new int[]{buffer.length});
ois = new ObjectInputStream(
new BufferedInputStream(
- new ByteArrayInputStream(
- uncompressed,0,uncompressed.length
- )
+ new ByteArrayInputStream( uncompressed,0,uncompressed.length )
)
);
passwords = (HashMap<String, String>)ois.readObject();
@@ -140,20 +144,8 @@
}
finally
{
- if(fis != null)
- {
- try
- {
- fis.close();
- }
- catch(Exception e)
- {
- }
- }
- if(ois != null)
- {
- try { ois.close(); } catch(Exception e) {}
- }
+ IOUtilities.closeQuietly(fis);
+ IOUtilities.closeQuietly(ois);
}
} //}}}
@@ -188,36 +180,9 @@
}
finally
{
- if(oos != null)
- {
- try
- {
- oos.close();
- }
- catch(Exception e)
- {
- }
- }
- if(baos != null)
- {
- try
- {
- baos.close();
- }
- catch(Exception e)
- {
- }
- }
- if(fos != null)
- {
- try
- {
- fos.close();
- }
- catch(Exception e)
- {
- }
- }
+ IOUtilities.closeQuietly(oos);
+ IOUtilities.closeQuietly(baos);
+ IOUtilities.closeQuietly(fos);
}
} //}}}
@@ -239,18 +204,19 @@
} //}}}
//{{{ getConnectionInfo() method
- public static ConnectionInfo getConnectionInfo(Component comp, FtpAddress address, boolean secure)
+ public static ConnectionInfo getConnectionInfo(Component comp, FtpAddress address)
{
- Log.log(Log.DEBUG, ConnectionManager.class, comp);
+ Log.log(Log.DEBUG, "ConnectionManager.getConnectionInfo", address);
String host, user;
String password;
-
+ boolean secure;
if(address != null)
{
host = address.getHost()+":"+address.getPort();
user = address.getUser();
password = address.getPassword();
+ secure = address.isSecure();
// Check for cached connection info
ConnectionInfo info = logins.get(host);
@@ -259,14 +225,16 @@
// Try to create connection from pre-defined params
String key = ConnectionManager.getStoredFtpKey(host, user);
+
if ( host!=null && user!=null && (password!=null || key!=null) ) {
- // TODO: try to use logins hash
- return new ConnectionInfo(secure, address.getHost(), address.getPort(), user, password, key);
+ Log.log(Log.DEBUG, ConnectionManager.class, "key="+key);
+ return new ConnectionInfo(address.isSecure(), address.getHost(), address.getPort(), user, password, key);
}
}
else {
host = user = password = null;
+ secure = false;
}
/* since this can be called at startup time,
@@ -315,7 +283,7 @@
connect = _connect;
if(!connect.checkIfOpen()) {
- Log.log(Log.DEBUG,ConnectionManager.class, "Connection " + connect + " expired");
+ Log.log(Log.DEBUG, ConnectionManager.class, "Connection " + connect + " expired");
try {
connect.logout();
} catch(IOException io) {
@@ -330,17 +298,13 @@
if(connect == null) {
Log.log(Log.DEBUG,ConnectionManager.class, Thread.currentThread() + ": Connecting to " + info);
- if(info.secure) {
- connect = new SFtpConnection(info);
- } else {
- try {
- connect = new FtpConnection(info);
- } catch (FtpLoginException e) {
- Log.log(Log.DEBUG, ConnectionManager.class, "catch FtpLoginException");
- //if (e.getResponse().getReturnCode() == "530")
- info.password = null; // necessary to show login dialog again instead of using save password again
- throw e;
- }
+ try {
+ connect = info.secure ? new SFtpConnection(info) : new FtpConnection(info);
+ } catch (IOException e) {
+ Log.log(Log.DEBUG, ConnectionManager.class, "catch " + e.getClass().getName() + " on "+ info);
+ info.password = null; // necessary to show login dialog again instead of using saved password again
+ //jEdit.setProperty("ftp.keys."+info.host+"."+info.user, null);
+ throw e;
}
connections.add(connect);
} else {
Modified: plugins/FTP/trunk/ftp/FtpVFS.java
===================================================================
--- plugins/FTP/trunk/ftp/FtpVFS.java 2010-06-18 19:21:38 UTC (rev 18110)
+++ plugins/FTP/trunk/ftp/FtpVFS.java 2010-06-18 21:03:22 UTC (rev 18111)
@@ -41,6 +41,7 @@
import org.gjt.sp.jedit.io.VFS;
import org.gjt.sp.jedit.io.VFSFile;
import org.gjt.sp.jedit.io.VFSManager;
+import org.gjt.sp.util.IOUtilities;
import org.gjt.sp.util.Log;
/**
@@ -57,8 +58,9 @@
public static final String EA_OWNER_USER = "user";
public static final String EA_OWNER_GROUP = "group";
- // same as File VFS permissions key!
+ // same as File VFS permissions key should be used!!!!
public static final String PERMISSIONS_PROPERTY = "FileVFS__perms";
+ public static final String MD5SUM_PROPERTY = "FtpVFS__MD5";
//{{{ FtpVFS method
public FtpVFS(boolean secure)
@@ -171,7 +173,7 @@
try {
Log.log(Log.DEBUG, this, "FtpVFS.createVFSSession("+path+", "+comp+")" );
ConnectionInfo info = ConnectionManager.getConnectionInfo(comp,
- path == null ? null : new FtpAddress(path), secure);
+ path == null ? null : new FtpAddress(path));
if(info == null)
return null;
@@ -214,8 +216,7 @@
} //}}}
//{{{ _listFiles() method
- public VFSFile[] _listFiles(Object _session, String url,
- Component comp) throws IOException
+ public VFSFile[] _listFiles(Object _session, String url, Component comp) throws IOException
{
VFSFile[] directory = DirectoryCache.getCachedDirectory(url);
if(directory != null)
@@ -319,6 +320,7 @@
{
Log.log(Log.DEBUG,this,path + " has permissions 0" + Integer.toString(dirEntry.permissions,8));
buffer.setIntegerProperty(PERMISSIONS_PROPERTY, dirEntry.permissions);
+ //buffer.setStringProperty(MD5_PROPERTY, );
} else {
//Log.log(Log.ERROR,this, path + " not open?");
}
@@ -440,10 +442,15 @@
} //}}}
+ /**{@inheritDoc}*/
public void _saveComplete(java.lang.Object session, Buffer buffer,
java.lang.String path, java.awt.Component comp)
throws java.io.IOException
{
+ //String s = new String(StandardUtilities.md5(buffer.getText()), "UTF-8");
+ //GUIUtilities.message(comp, s, null);
+ //buffer.setStringProperty(FtpVFS.MD5SUM_PROPERTY, StandardUtilities.md5(buffer.getText()) );
+ //Log.log(Log.DEBUG, "TEST", buffer.getStringProperty(FtpVFS.MD5SUM_PROPERTY));
}
/**{@inheritDoc}*/
@@ -457,7 +464,8 @@
return;
Buffer buffer = jEdit.getBuffer(path);
- String s = buffer.getText(0, buffer.getLength());
+ if (buffer == null)
+ return;
FtpAddress uri = new FtpAddress(path);
String backFile = "_"+uri.getScheme()+"_"+uri.getUser() + "@" + uri.getHost() + uri.getPath();
@@ -468,10 +476,10 @@
f.getParentFile().mkdirs();
- //if (!f.canWrite()) {
- // Log.log(Log.WARNING, this, "Can't write file " + backPath);
- // return;
- //}
+ if ( f.exists() && !f.canWrite()) {
+ Log.log(Log.ERROR, this, "Can't write file " + backPath);
+ return;
+ }
// Store file content
FileOutputStream os = new FileOutputStream(f);
@@ -480,11 +488,12 @@
Charset charset = Charset.forName(buffer.getStringProperty(JEditBuffer.ENCODING));
CharsetEncoder encoder = charset.newEncoder();
+ String s = buffer.getText();
CharBuffer buf = CharBuffer.allocate(s.length());
buf.append(s).flip();
channel.write(encoder.encode(buf));
- os.close();
+ IOUtilities.closeQuietly(os);
}
//{{{ Private members
Modified: plugins/FTP/trunk/ftp/SFtpConnection.java
===================================================================
--- plugins/FTP/trunk/ftp/SFtpConnection.java 2010-06-18 19:21:38 UTC (rev 18110)
+++ plugins/FTP/trunk/ftp/SFtpConnection.java 2010-06-18 21:03:22 UTC (rev 18111)
@@ -41,10 +41,10 @@
* @author Slava Pestov
* @author Vadim Voituk
*/
-public class SFtpConnection extends Connection implements UserInfo
+public class SFtpConnection extends Connection implements UserInfo, UIKeyboardInteractive
{
- SFtpConnection(final ConnectionInfo info) throws IOException
+ public SFtpConnection(final ConnectionInfo info) throws IOException
{
super(info);
try {
@@ -96,8 +96,7 @@
keyAttempts = 0;
session.setUserInfo(this);
- //FIXME: Timeout hardcoded to 60seconds
- session.connect(60000);
+ session.connect(ConnectionManager.connectionTimeout);
Channel channel = session.openChannel("sftp");
channel.connect();
@@ -239,8 +238,7 @@
public String resolveSymlink(String path, String[] name) throws IOException
{
- String returnValue = path;
- return returnValue;
+ return path;
}
void logout() throws IOException {
@@ -287,10 +285,11 @@
public String getPassword()
{
- return new String(info.password);
+ return info.password;
}
public boolean promptPassword(String message){ return true;}
+
public boolean promptPassphrase(String message)
{
Log.log(Log.DEBUG,this,message);
@@ -372,4 +371,14 @@
Log.log(Log.ERROR, this, e);
}
}
+
+ // See http://marc.info/?l=ant-dev&m=111959408515300&w=2
+ public String[] promptKeyboardInteractive(String destination, String name, String instruction, String[] prompt, boolean[] echo){
+ if(prompt.length!=1 || echo[0]!=false )
+ return null;
+ String[] response = new String[1];
+ response[0] = getPassword();
+ return response;
+ }
+
}
Modified: plugins/FTP/trunk/users-guide.xml
===================================================================
--- plugins/FTP/trunk/users-guide.xml 2010-06-18 19:21:38 UTC (rev 18110)
+++ plugins/FTP/trunk/users-guide.xml 2010-06-18 21:03:22 UTC (rev 18111)
@@ -164,6 +164,17 @@
<appendix id="changes"><title>Change log</title>
<itemizedlist>
+
+ <listitem>
+ <para>
+ <emphasis role="bold">Version 0.9.9</emphasis>
+ Requires Java 1.5+ and jEdit 4.4.2
+ </para>
+ <itemizedlist>
+ <listitem><para>Re-ask for connection details if no key-file exists</para></listitem>
+ <listitem><para>Fixed problem with authentication on some sFTP servers (promptKeyboardInteractive method impelented) </para></listitem>
+ </itemizedlist>
+ </listitem>
<listitem>
<para>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|