Introduction

SFTP stands for Secure File Transfer Protocol, which provides a secure encryption method for transferring files.

SFTP is a part of SSH and is a secure way to transfer files to a server. SFTP uses encryption to transmit authentication information and data, so using SFTP is very secure.

However, due to the use of encryption/decryption techniques in this transfer method, the transmission efficiency is much lower than that of ordinary FTP. If you require higher network security, you can use SFTP instead of FTP.

Usage

Introducing jsch

<dependency>
 <groupId>com.jcraft</groupId>
 <artifactId>jsch</artifactId>
 <version>0.1.54</version>
</dependency>

Usage

Sftp sftp = JschUtil.createSftp("172.0.0.1", 22, "root", "123456");
// Enter remote directory
sftp.cd("/opt/upload");
// Upload local file
sftp.put("e:/test.jpg", "/opt/upload");
// Download remote file
sftp.get("/opt/upload/test.jpg", "e:/test2.jpg");

// Close the connection
sftp.close();