StandardSftpConnection extends FileTransferConnection { public void setAuthentication(SftpAuthenticationProvider p) { this.authentication = p; } StandardSftpConnection();  StandardSftpConnection(ConfigBuilder config, SftpAuthenticationProvider prov); TimeInterval getSocketTimeout(); void setSocketTimeout(TimeInterval t); String getKnownHostsFile(); void setKnownHostsFile(String k); @Override int defaultControlPort(); ConfigBuilder getConfiguration(); void setConfiguration(ConfigBuilder repo); SftpAuthenticationProvider getAuthentication(); void setAuthentication(SftpAuthenticationProvider p);  }
@Test public void testConnectOnly_PasswordAuth() throws Exception { Assume.assumeTrue(areTestsEnabled()); StandardSftpConnection conn = createConnection(); try { conn.setAuthentication(new SftpPasswordAuthentication(PROPERTIES.getProperty(CFG_PASSWORD))); start(conn); FileTransferClient c = conn.connect(getDestinationString()); assertTrue(c.isConnected()); c.disconnect(); } finally { stop(conn); } }
@Test public void testConnectOnly_PasswordAuth_Override() throws Exception { Assume.assumeTrue(areTestsEnabled()); StandardSftpConnection conn = createConnection(); try { conn.setAuthentication(new SftpPasswordAuthentication("")); start(conn); FileTransferClient c = conn.connect(getDestinationStringWithOverridePassword()); assertTrue(c.isConnected()); c.disconnect(); } finally { stop(conn); } }
@Test public void testConnectOnly_Composite() throws Exception { Assume.assumeTrue(areTestsEnabled()); StandardSftpConnection conn = createConnection(); try { SftpAuthenticationWrapper auth = new SftpAuthenticationWrapper(new SftpKeyAuthentication(PROPERTIES.getProperty(CFG_PRIVATE_KEY_FILE), "PW:abde"), new SftpKeyAuthentication(PROPERTIES.getProperty(CFG_PRIVATE_KEY_FILE), PROPERTIES.getProperty(CFG_PRIVATE_KEY_PW))); conn.setAuthentication(auth); start(conn); FileTransferClient c = conn.connect(getDestinationString()); assertTrue(c.isConnected()); c.disconnect(); } finally { stop(conn); } }
@Test public void testConnectOnly_Composite_Fails() throws Exception { Assume.assumeTrue(areTestsEnabled()); StandardSftpConnection conn = createConnection(); SftpAuthenticationWrapper auth = new SftpAuthenticationWrapper(new SftpKeyAuthentication(PROPERTIES.getProperty(CFG_PRIVATE_KEY_FILE), "PW:abde"), new SftpKeyAuthentication("/some/path/that/does/not/exist", PROPERTIES.getProperty(CFG_PRIVATE_KEY_PW))); conn.setAuthentication(auth); try { start(conn); FileTransferClient c = conn.connect(getDestinationString()); fail(); } catch (IOException | PasswordException expected) { } finally { stop(conn); } }