<dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>3.6</version> </dependency> import org.apache.commons.net.ftp.FTPClient; public class FTPSyncExample { public static void main(String[] args) { FTPClient ftpClient = new FTPClient(); try { ftpClient.connect("ftp.example.com", 21); ftpClient.login("username", "password"); ftpClient.disconnect(); } catch (Exception e) { e.printStackTrace(); } } } boolean success = ftpClient.storeFile("remote-file.txt", new FileInputStream("local-file.txt")); if (success) { } else { } OutputStream outputStream = new FileOutputStream("local-file.txt"); boolean success = ftpClient.retrieveFile("remote-file.txt", outputStream); outputStream.close(); if (success) { } else { } ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.setControlEncoding("UTF-8");


上一篇:
下一篇:
切换中文