FTPClient 判断 ftp 目录是否存在

 /** 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;
        }

    }


调用

dirExist( hostname, port, username, password, "theFolderName" );

猜你喜欢

转载自blog.csdn.net/beguile/article/details/80184082
今日推荐