SFTP connection with SSH2 mode
949844Aug 20 2012 — edited Aug 23 2012I need to to make an SFTP connection to an SFTP site with the SSH2 mode using Java code in PL/SQL developer.
And the connection requires an RSA key to start with. We got the RSA key, but I have some trouble with the code.
Below is the code I've got so far, and I don't know how to turn on the SSH2 mode, and I don't know how to include the RSA key:
public static void SFTP_Login (java.lang.String inSite, int inPort, java.lang.String inUser_ID, java.lang.String inPassword)
throws Exception
{
System.setProperty("java.net.preferIPv4Stack", "TRUE");
try
{
conn = new Connection(inSite, inPort);
conn.connect();
String[] auth = conn.getRemainingAuthMethods(inUser_ID);
boolean tKeyboardInteractive = false;
boolean tPasswordAuthentication = false;
int i;
for (i = 0; i < auth.length; ++i)
{
if (auth.equals("password")) {
tPasswordAuthentication = true;
} else if (auth.equals("keyboard-interactive")) {
tKeyboardInteractive = true;
}
}
boolean isAuthenticated = false;
if (tPasswordAuthentication) {
isAuthenticated = conn.authenticateWithPassword(inUser_ID, inPassword);
} else if (tKeyboardInteractive) {
ki.response = inPassword;
isAuthenticated = conn.authenticateWithKeyboardInteractive(inUser_ID, ki);
}
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
}
catch(Exception ex)
{
SFTP_Logout_JAVA();
throw(ex);
}
}