Fixes for Mac OSX support

Greetings,

I thought you might be interested in accepting some changes I made for interoperability with Mac OS-X.  Keyboard Interactive login was broken, a small fix to ChannelSftp was required, and I stopped a stack trace from being logged when the session is closed.

My editor seems to have made extensive whitespace changes, so I've got the whitespace-ignoring diff below for you to review.

Regards,
--David Solin

$ git diff -w 4aad646d31bcf23f5918ac4e049db89374dcaac2..d5367c6780e06b60fa3442f088c549ec55336a5f
diff --git a/src/main/java/org/vngx/jsch/ChannelSftp.java b/src/main/java/org/vngx/jsch/ChannelSftp.java
index 74c013b..c2a6008 100644
--- a/src/main/java/org/vngx/jsch/ChannelSftp.java
+++ b/src/main/java/org/vngx/jsch/ChannelSftp.java
@@ -1913,8 +1913,8 @@ public final class ChannelSftp extends ChannelSession {
                        if( __closed ) {
                                return;
                        }
-                       __closed = true;
                        flush();
+                       __closed = true;
                        if( __monitor != null ) {
                                __monitor.end();
                        }
diff --git a/src/main/java/org/vngx/jsch/Session.java b/src/main/java/org/vngx/jsch/Session.java
index 742e4b7..cb9313c 100644
--- a/src/main/java/org/vngx/jsch/Session.java
+++ b/src/main/java/org/vngx/jsch/Session.java
@@ -47,6 +47,7 @@ import java.io.InterruptedIOException;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.Socket;
+import java.net.SocketException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
@@ -791,9 +792,14 @@ public final class Session implements Runnable {
                                }
                        }
                } catch(Exception e) {
+                       if (e instanceof SocketException && !_connected) {
+                               // just closing the session
+                       } else {
                        _keyExchange.kexCompleted();
                        if( JSch.getLogger().isEnabled(Logger.Level.INFO) ) {
-                               JSch.getLogger().log(Logger.Level.INFO, "Caught an exception, leaving main loop due to " + e, e)
+                                       JSch.getLogger().log(Logger.Level.INFO,
+                                               "Caught an exception, leaving main loop due to " + e, e);
+                               }
                        }
                }
                try {
diff --git a/src/main/java/org/vngx/jsch/userauth/UserAuthKeyboardInteractive.java b/src/main/java/org/vngx/jsch/userauth/UserAu
index 94fe2c4..13fc68e 100644
--- a/src/main/java/org/vngx/jsch/userauth/UserAuthKeyboardInteractive.java
+++ b/src/main/java/org/vngx/jsch/userauth/UserAuthKeyboardInteractive.java
@@ -47,10 +47,12 @@ public final class UserAuthKeyboardInteractive extends UserAuth {

        @Override
        public boolean authUser(Session session, byte[] password) throws Exception {
+               super.authUser(session, password);
                if( !(_userinfo instanceof UIKeyboardInteractive) ) {
                        return false;   // Fail if no keyboard interactive interface available
+               } else if (password == null) {
+                       password = _userinfo.getPassword().getBytes();
                }
-               super.authUser(session, password);
                _passwordPrompt = createPasswordPrompt(session);

                boolean cancel = false;