Skip to main content

Posts

Showing posts from 2022

Connecting to SFTP server using 2-Factor authentication In Java

  In this article we will connect to SFTP server using both password and SSH key as the authentication method. This is also referred to as 2-Factor Authentication with SFTP. We will use Apache's VFS library to establish the connection. Following class shows how to: Connect to SFTP server Navigate to a desired folder List of files in a folder First we need to add the Apache VFS dependency to our project. For maven it can be added to the pom.xml file. Latest dependency can be found at:  https://mvnrepository.com/artifact/org.apache.commons/commons-vfs2 <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-vfs2 --> <dependency> <groupId> org.apache.commons </groupId> <artifactId> commons-vfs2 </artifactId> <version> 2.9.0 </version> </dependency> Now let's look at the actual code, in SftpWithTwoFactorAuth class below. /** * This class uses Apache's VFS project to connect to remote SFTP server using

Connecting to Remote SFTP server using SSH key In Java

 In this article we will connect to SFTP server using username and SSH key as the authentication method. We will use Apache's VFS library to establish the connection. Following class show how to: Connect to SFTP server Navigate to a desired folder List of files in a folder First we need to add the Apache VFS dependency to our project. For maven it can be added to the pom.xml file. Latest dependency can be found at:  https://mvnrepository.com/artifact/org.apache.commons/commons-vfs2 <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-vfs2 --> <dependency> <groupId> org.apache.commons </groupId> <artifactId> commons-vfs2 </artifactId> <version> 2.9.0 </version> </dependency> Now let's look at the actual code, in SftpWithSshKey class below. /** * This class uses Apache's VFS project to connect to remote SFTP server using * username and SSH key based authentication. * <p> * Maven Dependen

Connecting to Remote SFTP server With Password Only In Java

 In this article we will connect to SFTP server using only password as the authentication method. We will use Apache's VFS library to establish the connection. Following class show how to: Connect to SFTP server Navigate to a desired folder List of files in a folder First we need to add the Apache VFS dependency to our project. For maven it can be added to the pom.xml file. Latest dependency can be found at:  https://mvnrepository.com/artifact/org.apache.commons/commons-vfs2 <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-vfs2 --> <dependency> <groupId> org.apache.commons </groupId> <artifactId> commons-vfs2 </artifactId> <version> 2.9.0 </version> </dependency> Now let's look at the actual code, in SftpWithPassword class below. /** * This class uses Apache's VFS project to connect to remote SFTP server using * username and password based authentication. * <p> * Maven Dependency: