Modern Java: Download and Upload Files from SFTP Servers from Java using the sshj library

Опубликовано: 26 Февраль 2022
на канале: Productivity for Programmers
4,756
65

In my first video on writing SFTP clients in Java I used a library called jsch. jsch does what it claims but it does feel a little bit dated. The Java library that I’m going to show today is called sshj (https://github.com/hierynomus/sshj) and it has a much more modern feel to it.

Advantages of using sshj over jsch:
Supports "BEGIN OPENSSH PRIVATE KEY" style private keys out of the box
Uses the Java collections framework e.g. java.util.List instead of java.util.Vector
Updated more frequently

While not necessary, if you enjoyed this video, buying me a coffee is greatly appreciated!
https://www.buymeacoffee.com/prodprog... (no refunds)

00:00 Intro
00:30 Add Gradle dependency
02:05 Connecting to an SFTP Server
06:20 Specifying the public key algorithm to authenticate the host
08:20 Password based authentication
09:03 Key based authentication
10:32 Creating the SFTP client, listing the directory and changing the current directory
13:10 Downloading a file - to a file and to a buffer
15:27 Creating remote directories and uploading content - from a file and from an in memory buffer

IntelliJ Live Code Templates:
https://gist.github.com/productivity-...

SSHJ:
https://github.com/hierynomus/sshj

Icon Credits:
Sftp Flat Icon by Alexiuz AS
https://iconscout.com/icons/sftp
https://iconscout.com/contributors/WH...