Forum Stats

  • 3,874,115 Users
  • 2,266,686 Discussions
  • 7,911,730 Comments

Discussions

Making SFTP connection in SSH2 mode

949844
949844 Member Posts: 15
edited Aug 20, 2012 6:51PM in XQuery
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[i].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);
}
}

Answers

This discussion has been closed.