Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SFTP connection with SSH2 mode

949844Aug 20 2012 — edited Aug 23 2012
I 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);
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 20 2012
Added on Aug 20 2012
12 comments
1,654 views