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
Articles on software development