implementation 'commons-net:commons-net:3.3'
public void ftpTest(){
FTPClient ftpClient = new FTPClient();
FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
conf.setServerLanguageCode("zh");
ftpClient.setControlEncoding("GBK");
ftpClient.configure(conf);
try {
ftpClient.connect("ip",2121);
ftpClient.login("root","root");
int reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
System.out.println("断开连接");
ftpClient.disconnect();
//return false
}
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
ftpClient.changeWorkingDirectory("/spider03");
FTPFile[] files2 = ftpClient.listFiles();
for(FTPFile file:files2){
System.out.println(file.getName());
}
}catch (SocketException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}