Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions javasource/sftpconnection/helpers/HandleFileSftp.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,22 @@
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;

public class HandleFileSftp {

public static HashMap<String, Session> userSession = new HashMap<String, Session>();

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 {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -226,6 +233,7 @@ public static ArrayList<IMendixObject> getFileListFromSFTP(SFTPConfiguration sft
String remoteSource = sftpConfiguration.getRemoteSourceFolder(context);

Session session = createSession(sftpConfiguration, context);
session.connect();
ChannelSftp sftpChannel = createSFTPChannel(session);

try {
Expand Down Expand Up @@ -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;
}
}

}
}