diff --git a/javasource/sftpconnection/helpers/HandleFileSftp.java b/javasource/sftpconnection/helpers/HandleFileSftp.java index bcce7c1..7fbee92 100644 --- a/javasource/sftpconnection/helpers/HandleFileSftp.java +++ b/javasource/sftpconnection/helpers/HandleFileSftp.java @@ -37,6 +37,7 @@ import com.jcraft.jsch.SftpException; import com.mendix.core.Core; import com.mendix.core.CoreException; +import com.mendix.logging.ILogNode; import com.mendix.systemwideinterfaces.MendixRuntimeException; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.systemwideinterfaces.core.IMendixObject; @@ -44,6 +45,14 @@ public class HandleFileSftp { public static HashMap userSession = new HashMap(); + + private static MendixLogger mxLogger; + static ILogNode logger = Core.getLogger("SFTP module"); + + static { + mxLogger = new MendixLogger(); + JSch.setLogger(mxLogger); + } public static ChannelSftp createSFTPChannel(Session session) throws JSchException { @@ -121,9 +130,7 @@ public static Session createSession(SFTPConfiguration sftpConfiguration, IContex JSch jsch = new JSch(); java.util.Properties config = new java.util.Properties(); - - - + config.put("PreferredAuthentications", "publickey,password"); // this setting forces to use only (by the module) supported authentication methods and avoids timeouts when trying others if (!sftpConfiguration.getStrictHostkeyChecking()) { config.put("StrictHostKeyChecking", "no"); @@ -226,6 +233,7 @@ public static ArrayList getFileListFromSFTP(SFTPConfiguration sft String remoteSource = sftpConfiguration.getRemoteSourceFolder(context); Session session = createSession(sftpConfiguration, context); + session.connect(); ChannelSftp sftpChannel = createSFTPChannel(session); try { @@ -366,4 +374,35 @@ public static Boolean generateKeyPair(PrivateKey privateKey, PublicKey publicKey return true; } + + public static class MendixLogger implements com.jcraft.jsch.Logger { + + + @Override + public boolean isEnabled(int arg0) { + return true; + } + + @Override + public void log(int level, String message) { + switch (level) { + case DEBUG: + logger.trace(message); + break; + case INFO: + logger.debug(message); + break; + case WARN: + logger.warn(message); + break; + case ERROR: + logger.error(message); + break; + case FATAL: + logger.critical(message); + break; + } + } + + } }