其他分享
首页 > 其他分享> > ftp连接

ftp连接

作者:互联网

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();
}

标签:ftp,FTPClientConfig,FILE,printStackTrace,conf,连接,ftpClient,out
来源: https://www.cnblogs.com/hai-/p/14874255.html