package xfire; import java.io.FileOutputStream; import java.io.IOException; import org.apache.commons.net.ftp.FTPClient; public class java { /** * FTP下载单个文件测试 */ public static void fileDownloadByFtp() { FTPClient ftpClient = new FTPClient(); FileOutputStream fos = null; try { ftpClient.connect("192.85.1.9"); ftpClient.login("zhangzhenmin", "62672000"); String remoteFileName = "/home/zhangzhenmin/test_back_081901.sql"; // fos = new FileOutputStream("E:/test/test_back_081901.sql"); fos = new FileOutputStream("H:/test/test_back_081901.sql"); ftpClient.setBufferSize(1024); // 设置文件类型(二进制) ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); ftpClient.retrieveFile(remoteFileName, fos); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("FTP客户端出错!", e); } try { ftpClient.disconnect(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("关闭FTP连接发生异常!", e); } } public static void main(String[] args) { fileDownloadByFtp(); } }
时间: 2024-11-05 13:43:25