/** FTPClient 判断 ftp 目录是否存在 */
public static boolean dirExist( String hostname, int port, String username, String password, String dir ) {
FTPClient ftpClient = new FTPClient();
try {
//连接FTP服务器
ftpClient.connect(hostname, port);
//登录FTP服务器
ftpClient.login(username, password);
//验证FTP服务器是否登录成功
int replyCode = ftpClient.getReplyCode();
if(!FTPReply.isPositiveCompletion(replyCode)){
return false;
}
return ftpClient.changeWorkingDirectory(dir);
} catch (IOException e) {
return false;
}
public static boolean dirExist( String hostname, int port, String username, String password, String dir ) {
FTPClient ftpClient = new FTPClient();
try {
//连接FTP服务器
ftpClient.connect(hostname, port);
//登录FTP服务器
ftpClient.login(username, password);
//验证FTP服务器是否登录成功
int replyCode = ftpClient.getReplyCode();
if(!FTPReply.isPositiveCompletion(replyCode)){
return false;
}
return ftpClient.changeWorkingDirectory(dir);
} catch (IOException e) {
return false;
}
}
调用
dirExist( hostname, port, username, password, "theFolderName" );