투케이2K

861. (Android/Java) [commons-net-3.6.jar] FTP 서버 파일 존재 여부 확인 수행 - getFtpFileExists 본문

Android

861. (Android/Java) [commons-net-3.6.jar] FTP 서버 파일 존재 여부 확인 수행 - getFtpFileExists

투케이2K 2024. 9. 1. 09:54
반응형

[개발 환경 설정]

개발 툴 : AndroidStudio

개발 언어 : Java / Kotlin

 

[소스 코드]

 

    // ------------------------------------------------------------------------------------------
    // TODO [FTP 서버 파일 목록 확인]
    // ------------------------------------------------------------------------------------------
    public synchronized boolean getFtpFileExists(String ftpPath, String fileName) {
        S_Log._D_("FTP 서버 파일 존재 확인 수행", new String[]{ "ftpPath :: " + String.valueOf(ftpPath), "fileName :: " + String.valueOf(fileName) });


        /*
        D  ===================================================================
        [LOG :: CLASS PLACE :: com.example.javaproject.C_Module.C_FTP_Client_Module.getFtpFileExists(C_FTP_Client_Module.java:366)]
        ----------------------------------------------------
        [LOG :: NOW TIME :: 2024-08-31 18:54:07 토요일]
        ----------------------------------------------------
        [LOG :: DESCRIPTION :: FTP 서버 파일 존재 확인 수행]
        ----------------------------------------------------
        [LOG :: ftpPath :: /html]
        ----------------------------------------------------
        [LOG :: fileName :: functionTest.html]
        D  ===================================================================


        D  ===================================================================
        [LOG :: CLASS PLACE :: com.example.javaproject.C_Module.C_FTP_Client_Module.getFtpFileExists(C_FTP_Client_Module.java:391)]
        ----------------------------------------------------
        [LOG :: NOW TIME :: 2024-08-31 18:54:07 토요일]
        ----------------------------------------------------
        [LOG :: DESCRIPTION :: FTP 서버 파일 존재 확인 성공]
        ----------------------------------------------------
        [LOG :: true]
        D  ===================================================================
        // */


        // [리턴 변수 선언]
        boolean result = false;

        // [로직 처리 수행]
        try {

            if (mMainCtx != null && ftpClient != null && isConnection == true){

                if (ftpClient.isConnected() == true){

                    if (C_Util.stringNotNull(ftpPath) == true && C_Util.stringNotNull(fileName) == true){

                        FTPFile [] files = ftpClient.listFiles(ftpPath); // [특정 경로 지정] : [/html]

                        if (files != null && files.length > 0){

                            for (int i=0; i<files.length; i++){
                                if (String.valueOf(files[i].getName()).equals(fileName) == true){
                                    result = true;
                                    break;
                                }
                            }

                            S_Log._E_("FTP 서버 파일 존재 확인 성공", new String[]{ String.valueOf(result) });

                        }
                        else {
                            S_Log._E_("FTP 서버 파일 존재 확인 에러 발생", new String[]{ "Error :: FTPFile Is Null" });
                        }

                    }
                    else {
                        S_Log._E_("FTP 서버 파일 존재 확인 에러 발생", new String[]{ "Error :: Input Data Is Null" });
                    }

                }
                else {
                    S_Log._E_("FTP 서버 파일 존재 확인 에러 발생", new String[]{ "Error :: ftpClient.isConnected() == false" });
                }

            }
            else {
                S_Log._E_("FTP 서버 파일 목록 존재 에러 발생", new String[]{ "Error :: mMainCtx Is Null or ftpClient Not Null or isConnection false" });
            }

        }
        catch (Exception e){
            e.printStackTrace();
        }

        // [리턴 결과 반환]
        return result;
    }

 

반응형
Comments