前言
连接ftp服务器方式:通过Java代码连接ftp服务器
下载文件实现方式:
public void downloadFile(String localPath, String ftpPath, String fileName) { if (!localPath.endsWith("/")) { localPath = localPath + "/"; } FTPClient client = ftpClientManager.getClient(); File localFile = new File(localPath + fileName); try { client.changeWorkingDirectory(ftpPath); OutputStream is = new FileOutputStream(localFile); client.retrieveFile(fileName, is); is.close(); logger.info("success to download file: " + localFile.getAbsolutePath()); } catch (Exception e) { logger.error("faild to download file " + localFile.getAbsolutePath() + " because " + e.getMessage()); System.exit(0); } }