java FTP和SFTP相关操作
java FTP和SFTP相关操作
Apache FtpClient使用
添加依赖
<dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>3.6</version> </dependency>
链接并登录服务器
1 /** 2 * 连接并登录服务器 3 * 4 * @throws IOException 5 */ 6 public static void connectAndLogin() throws IOException { 7 FTPClient ftpClient = new FTPClient(); 8 ftpClient.connect("192.168.100.210", 21); 9 boolean isLogin = ftpClient.login("ftp", "ftp123"); 10 if (isLogin) { 11 System.out.println("登录成功!"); 12 } else { 13 System.out.println("登录失败!"); 14 } 15 }