我使用apache commons-net從FTP服務器下載文件。這很多工作正常。我遇到問題的部分是使用JProgressBar
顯示下載進度。如何在從FTP服務器下載文件時顯示JProgressBar
下面的代碼演示如何,我下載我需要的文件:
public void download() {
try {
FTPClient ftpClient = new FTPClient();
String fileName = "OFMEX_MANUFACTURING.jar";
ftpClient.connect("192.168.1.242");
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode)) {
JOptionPane.showMessageDialog(null, "Server Down");
}
boolean login = ftpClient.login("bioftp", "bioftp");
boolean changeWorkingDirectory = ftpClient.changeWorkingDirectory("ofmex\\Linux\\");
boolean setFileType = ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
OutputStream data = (OutputStream) new FileOutputStream(fileName);
ftpClient.retrieveFile(fileName, data);
ftpClient.abort();
} catch (Exception e) {
e.printStackTrace();
}
}