블로그 이미지
박공명

카테고리

분류 전체보기 (99)
된장 (7)
Dev (60)
꼐..꼐임 (6)
식탐 (18)
우리 (0)
Etc (8)
개인자료 (0)
Total
Today
Yesterday

ftp 파일삭제.

Dev/Java / 2010. 3. 24. 16:21

ftp기능을 만지다보니 생각지도못하게

원격지파일 삭제기능을 지원하는 라이브러리가 없는거 같더라.

뭐 내가 못찾았을수도 있고...

한 4가지를 모두 사용해보구 되는거 한개를 찾았다.

org.apache.commons.net.ftp.FTP

아파치꺼네


public void deleteFtp() throws Exception {
  
    FTPClient client = null;
    BufferedInputStream bis = null;
    try {
     client = new FTPClient();

  client.setControlEncoding("euc-kr");
  client.connect(server , Integer.parseInt(port));
  int resultCode = client.getReplyCode();
  
  if(FTPReply.isPositiveCompletion(resultCode) == false){
   throw new Exception("FTP 서버에 연결할 수 없습니다.");
  }
  else {
   client.setSoTimeout(5000);
   boolean isLogin = client.login(user, password1);
   if(isLogin == false) {
    throw new Exception("FTP 서버에 로그인 할 수 없습니다.");
   }
   client.setFileType(FTP.BINARY_FILE_TYPE);
   String deleteFile = serverPath + "/" + serverFile;
   System.out.println("delete path = " + deleteFile);
  boolean delflag =  client.deleteFile(deleteFile);
  //System.out.println("파일 전송 성공여부 : "+isSuc);
  if(delflag == false) {
   throw new Exception("파일삭제에 실패 하였습니다.");
  }
 
      client.logout();
     }
    } catch (Exception e) {
     e.printStackTrace();
     throw e;
    }
    finally {
    
     if(bis != null) {
      try {bis.close(); } catch (Exception e) { }
     }
     if(client != null && client.isConnected()) {
      try { client.disconnect(); } catch (Exception e) {}
     }
    }
   
   }


단지 파일삭제기능을 수행하는 메소드가 필요할뿐인데 왜 다른데서는 못찾았을까??? 정말없나?

'Dev > Java' 카테고리의 다른 글

java.sql.SQLException: 스트림이 이미 종료되었습니다  (0) 2010.03.25
Full GC  (0) 2010.03.25
ftp upload  (0) 2010.03.24
정규표현식을 사용하여 스크립트 제거  (1) 2010.03.24
이미지 리사이징 , image resize  (0) 2010.03.24
Posted by 박공명
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함