How to use setKnownHosts method of com.consol.citrus.ftp.client.SftpClient class

Best Citrus code snippet using com.consol.citrus.ftp.client.SftpClient.setKnownHosts

Source:SftpClient.java Github

copy

Full Screen

...196 }197 @Override198 protected void connectAndLogin() {199 if (getEndpointConfiguration().isStrictHostChecking()) {200 setKnownHosts();201 }202 if (session == null || !session.isConnected()) {203 try {204 if (StringUtils.hasText(getEndpointConfiguration().getPrivateKeyPath())) {205 ssh.addIdentity(getPrivateKeyPath(), getEndpointConfiguration().getPrivateKeyPassword());206 }207 } catch (JSchException e) {208 throw new CitrusRuntimeException("Cannot add private key " + getEndpointConfiguration().getPrivateKeyPath() + ": " + e,e);209 } catch (IOException e) {210 throw new CitrusRuntimeException("Cannot open private key file " + getEndpointConfiguration().getPrivateKeyPath() + ": " + e,e);211 }212 try {213 session = ssh.getSession(getEndpointConfiguration().getUser(), getEndpointConfiguration().getHost(), getEndpointConfiguration().getPort());214 if (StringUtils.hasText(getEndpointConfiguration().getPassword())) {215 session.setUserInfo(new UserInfoWithPlainPassword(getEndpointConfiguration().getPassword()));216 session.setPassword(getEndpointConfiguration().getPassword());217 }218 session.setConfig(KnownHostsServerKeyVerifier.STRICT_CHECKING_OPTION, getEndpointConfiguration().isStrictHostChecking() ? "yes" : "no");219 session.setConfig("PreferredAuthentications", getEndpointConfiguration().getPreferredAuthentications());220 getEndpointConfiguration().getSessionConfigs().entrySet()221 .stream()222 .peek(entry -> log.info(String.format("Setting session configuration: %s='%s'", entry.getKey(), entry.getValue())))223 .forEach(entry -> session.setConfig(entry.getKey(), entry.getValue()));224 session.connect((int) getEndpointConfiguration().getTimeout());225 Channel channel = session.openChannel("sftp");226 channel.connect((int) getEndpointConfiguration().getTimeout());227 sftp = (ChannelSftp) channel;228 log.info("Opened secure connection to FTP server");229 } catch (JSchException e) {230 throw new CitrusRuntimeException(String.format("Failed to login to FTP server using credentials: %s:%s", getEndpointConfiguration().getUser(), getEndpointConfiguration().getPassword()), e);231 }232 }233 }234 private void setKnownHosts() {235 if (getEndpointConfiguration().getKnownHosts() == null) {236 throw new CitrusRuntimeException("Strict host checking is enabled but no knownHosts given");237 }238 try {239 ssh.setKnownHosts(FileUtils.getFileResource(getEndpointConfiguration().getKnownHosts()).getInputStream());240 } catch (JSchException e) {241 throw new CitrusRuntimeException("Cannot add known hosts from " + getEndpointConfiguration().getKnownHosts() + ": " + e,e);242 } catch (IOException e) {243 throw new CitrusRuntimeException("Cannot find known hosts file " + getEndpointConfiguration().getKnownHosts() + ": " + e,e);244 }245 }246 protected String getPrivateKeyPath() throws IOException {247 if (!StringUtils.hasText(getEndpointConfiguration().getPrivateKeyPath())) {248 return null;249 } else if (getEndpointConfiguration().getPrivateKeyPath().startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {250 File priv = File.createTempFile("citrus-sftp","priv");251 InputStream is = getClass().getClassLoader().getResourceAsStream(getEndpointConfiguration().getPrivateKeyPath().substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()));252 if (is == null) {253 throw new CitrusRuntimeException("No private key found at " + getEndpointConfiguration().getPrivateKeyPath());...

Full Screen

Full Screen

Source:SftpClientBuilder.java Github

copy

Full Screen

...115 * @param knownHosts116 * @return117 */118 public SftpClientBuilder knownHosts(String knownHosts) {119 endpoint.getEndpointConfiguration().setKnownHosts(knownHosts);120 return this;121 }122 /**123 * Sets the preferred authentications property.124 * @param preferredAuthentications125 * @return126 */127 public SftpClientBuilder preferredAuthentications(String preferredAuthentications) {128 endpoint.getEndpointConfiguration().setPreferredAuthentications(preferredAuthentications);129 return this;130 }131 /**132 * Sets the sessionConfigs property.133 * @param sessionConfigs...

Full Screen

Full Screen

setKnownHosts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ftp.client;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;4import com.consol.citrus.dsl.runner.TestRunner;5import com.consol.citrus.ftp.message.FtpMessageHeaders;6import com.consol.citrus.testng.CitrusParameters;7import org.testng.annotations.Test;8import java.io.File;9import java.io.IOException;10import static com.consol.citrus.actions.CreateVariablesAction.Builder.createVariable;11public class SftpClientSetKnownHostsIT extends JUnit4CitrusTestDesigner {12 @CitrusParameters({"host", "port", "username", "password", "localKnownHostsFile"})13 public void sftpClientSetKnownHostsIT(String host, String port, String username, String password, String localKnownHostsFile) throws IOException {14 variable("host", host);15 variable("port", port);16 variable("username", username);17 variable("password", password);18 variable("localKnownHostsFile", localKnownHostsFile);19 $(createVariable("localKnownHostsFileContent")20 .value("localhost ssh-rsa

Full Screen

Full Screen

setKnownHosts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ftp.client;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.springframework.core.io.ClassPathResource;4import org.springframework.core.io.Resource;5import org.testng.annotations.Test;6public class SetKnownHostsIT extends TestNGCitrusTestDesigner {7 public void setKnownHostsIT() {8 variable("sftpHost", "

Full Screen

Full Screen

setKnownHosts

Using AI Code Generation

copy

Full Screen

1SftpClient sftpClient = new SftpClient();2sftpClient.setKnownHosts("known_hosts");3SftpClient sftpClient = new SftpClient();4sftpClient.setKnownHosts("known_hosts");5SftpClient sftpClient = new SftpClient();6sftpClient.setKnownHosts("known_hosts");7SftpClient sftpClient = new SftpClient();8sftpClient.setKnownHosts("known_hosts");9SftpClient sftpClient = new SftpClient();10sftpClient.setKnownHosts("known_hosts");11SftpClient sftpClient = new SftpClient();12sftpClient.setKnownHosts("known_hosts");13SftpClient sftpClient = new SftpClient();14sftpClient.setKnownHosts("known_hosts");15SftpClient sftpClient = new SftpClient();16sftpClient.setKnownHosts("known_hosts");17SftpClient sftpClient = new SftpClient();18sftpClient.setKnownHosts("known_hosts");19SftpClient sftpClient = new SftpClient();

Full Screen

Full Screen

setKnownHosts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ftp.client;2import com.consol.citrus.testng.AbstractTestNGUnitTest;3import org.testng.annotations.Test;4public class SetKnownHostsTest extends AbstractTestNGUnitTest {5public void testSetKnownHosts() {6SftpClient sftpClient = new SftpClient();7sftpClient.setKnownHosts("localhost");8}9}

Full Screen

Full Screen

setKnownHosts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ftp;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.springframework.beans.factory.annotation.Autowired;4import org.springframework.beans.factory.annotation.Qualifier;5import org.testng.annotations.Test;6public class SftpClientKnownHostsIT extends TestNGCitrusTestDesigner {7 @Qualifier("sftpKnownHostsClient")8 private SftpClient sftpClient;9 public void testSftpClientKnownHosts() {10 sftpClient.setKnownHosts("classpath:com/consol/citrus/ftp/known_hosts");11 sftpClient.connect();12 sftpClient.sendFile("classpath:com/consol/citrus/ftp/test.txt", "test.txt");13 sftpClient.disconnect();14 }15}16package com.consol.citrus.ftp;17import co

Full Screen

Full Screen

setKnownHosts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ftp.client;2import com.consol.citrus.ftp.message.FtpMessageHeaders;3import com.consol.citrus.testng.AbstractTestNGCitrusTest;4import org.springframework.beans.factory.annotation.Autowired;5import org.springframework.core.io.ClassPathResource;6import org.springframework.ftp.core.FtpTemplate;7import org.springframework.test.context.ContextConfiguration;8import org.testng.annotations.Test;9import com.consol.citrus.dsl.builder.B

Full Screen

Full Screen

setKnownHosts

Using AI Code Generation

copy

Full Screen

1public class 3{2 public static void main(String[] args) {3 SftpClient ftpClient = new SftpClient();4 ftpClient.setUser("user");5 ftpClient.setPassword("password");6 ftpClient.setKnownHosts("/home/user/.ssh/known_hosts");7 ftpClient.connect();8 ftpClient.disconnect();9 }10}11public class 4{12 public static void main(String[] args) {13 SftpClient ftpClient = new SftpClient();14 ftpClient.setUser("user");15 ftpClient.setPassword("password");16 ftpClient.setPrivateKey("/home/user/.ssh/id_rsa");17 ftpClient.connect();18 ftpClient.disconnect();19 }20}21public class 5{22 public static void main(String[] args) {23 SftpClient ftpClient = new SftpClient();24 ftpClient.setUser("user");25 ftpClient.setPassword("password");26 ftpClient.setPrivateKey("/home/user/.ssh/id_rsa");27 ftpClient.setPrivateKeyPassword("password");28 ftpClient.connect();29 ftpClient.disconnect();30 }31}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful