JSch sftp 上传/下载进度
我是JSch和java的新手。我设法得到了一些代码并以某种方式理解它,但我被困在一点上。下面的代码从SSH服务器下载文件,但我需要显示文件复制百分比的进度表。我能做到吗?我将非常感谢您的帮助。
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpProgressMonitor;
public class SFTPExample {
public static void main(String args[]) throws Exception {
String user = "root";
String password = "password";
String host = "192.168.0.5";
int port = 22;
String knownHostsFilename = "/home/world/.ssh/known_hosts";
String sourcePath = "/media/nfs/genotype.txt";
String destPath = "genotype.txt";
JSch jsch = new JSch();
jsch.setKnownHosts(knownHostsFilename);
Session session = jsch.getSession(user, host, port);
session.setPassword(password);
session.connect();
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
System.out.println("Downloading test file");
sftpChannel.get(sourcePath, destPath);
sftpChannel.exit();
session.disconnect();
}
}