private FTPClient initFtpClient() {
String ip = "127.0.0.1";
Integer port = 21;
String username = "test";
String password = "test";
FTPClient ftp = new FTPClient();
try {
int reply;
ftp.connect(ip, port);
boolean flag = ftp.login(username, password);// 登录
if (!flag) {
if (ftp.isConnected()) {
ftp.disconnect();
}
LOGGER.error("init ftp client error,login ftp failed");
return null;
}
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
LOGGER.error("init ftp client error,impositive ftp connection");
return null;
}
ftp.setControlEncoding("UTF-8");
ftp.setFileType(FTP.BINARY_FILE_TYPE);
//ftp.enterLocalPassiveMode();
return ftp;
} catch (Exception e) {
LOGGER.error("init ftp client error");
return null;
}
}