import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; public class FTPExample { public static void main(String[] args) { String server = "ftp.example.com"; int port = 21; String username = "username"; String password = "password"; FTPClient ftpClient = new FTPClient(); try { ftpClient.connect(server, port); int replyCode = ftpClient.getReplyCode(); if (FTPReply.isPositiveCompletion(replyCode)) { boolean success = ftpClient.login(username, password); if (success) { System.out.println("Successfully logged in."); ftpClient.logout(); ftpClient.disconnect(); } else { System.out.println("Login failed."); } } else { System.out.println("FTP server refused connection."); } } catch (Exception e) { e.printStackTrace(); } } }


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