我正在使用 apache commons-net 从 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();
}
}