Example #1
0
  /** 파일전송 */
  private static boolean setUploadFile(FTPClient ftp, String filename) throws Exception {
    boolean issend = false;
    FileInputStream fis = null; // File Input Stream
    File uploadfile = new File(filename); // File 객체
    try {
      fis = new FileInputStream(uploadfile); // 업로드할 File 생성
      boolean sf = ftp.storeFile(uploadfile.getName(), fis); // File업로드

      if (sf == true) {
        Log.debug("파일 업로드 성공");
        issend = true;
      } else {
        Log.debug("파일 업로드 실패");
        throw new Exception("File Upload Fail...");
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      throw ex;
    } finally {
      if (fis != null) {
        try {
          fis.close(); // Stream 닫기
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
    try {
      ftp.logout(); // FTP Log Out
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (ftp != null && ftp.isConnected()) {
        try {
          ftp.disconnect(); // 접속 끊기
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    return issend;
  }
Example #2
0
  /** 파일다운로드 */
  private static boolean getDownloadFile(FTPClient ftp, String filename) throws Exception {
    boolean isreceive = false;

    FileOutputStream fos = null; // File Output Stream
    File downloadfile = new File(filename); // File 객체
    try {
      fos = new FileOutputStream(downloadfile); // 다운로드할 File 생성
      ftp.retrieveFile(downloadfile.getName(), fos);
      isreceive = true;
    } catch (Exception ex) {
      ex.printStackTrace();
      throw ex;
    } finally {
      if (fos != null) {
        try {
          fos.close(); // Stream 닫기
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
    try {
      ftp.logout(); // FTP Log Out
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (ftp != null && ftp.isConnected()) {
        try {
          ftp.disconnect(); // 접속 끊기
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    return isreceive;
  }