展开全部
前段时间正好看了这个。
这个文档非常好。有什么看e69da5e887aa3231313335323631343130323136353331333335316631不懂的再问吧。
主要是使用 org.apache.commons.net.ftp.FTPClient 和 org.apache.commons.net.ftp.FTP 类。
核心代码:ftpClient.connect(server, port);
ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
// APPROACH #1: using retrieveFile(String, OutputStream)
String remoteFile1 = "/test/video.mp4";
File downloadFile1 = new File("D:/Downloads/video.mp4");
OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1));
boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1);
outputStream1.close();
if (success) {
System.out.println("File #1 has been downloaded successfully.");
}