所需jar包,及下载地址
jsch:Maven Repository: com.jcraft » jsch » 0.1.55 (mvnrepository.com)
创建 DownloadDirectoryFromLinux 工具类,用来下载文件
public class DownloadDirectoryFromLinux {
public void main() {
String hostname = "linux的ip地址(10.***.*.***)";
int port = 端口号(22);
String username = "用户名(root)";
String password = "密码";
String remoteDirPath = "linux需要下载的文件目录(/root/test)";
String localDirPath = "保存到本地的文件目录(D:\\Desktop\\test\\)";
JSch jsch = new JSch();
Session session = null;
Channel channel = null;
ChannelSftp channelSftp = n