ftp

来源:互联网 发布:信诺尔软件 编辑:程序博客网 时间:2024/06/07 22:32
public static boolean deleteDir(String fileName,String modId){
  Map map = commonConfJdbcDao.getFtpConfig(modId);
  if(map == null || map.size() < 1){
   return false;
  }
  String ip = map.get("ip") == null ? "" : map.get("ip").toString();
  String account = map.get("account") == null ? "" : map.get("account").toString();
  String password = map.get("password") == null ? "" : map.get("password").toString();
  String path_root = map.get("path_root") == null ? "" : map.get("path_root").toString();
  
  
  if( "".equals(ip) || "".equals(account) || "".equals(password)){
   return false;
  }
  FtpUtil ftp = new FtpUtil(ip,account,password);
  if(!ftp.connectServer()){
   return false;
  }
  
  boolean flag =  ftp.deleteDirectory(path_root + "/" + fileName);
  
  ftp.closeServer();
  
  return flag;
 }
 
 /**
  * 删除文件夹及文件夹中的文件
  * @param fileName
  * @param modId
  * @return
  */
 public static boolean deleteDirAndFile(String fileName,String modId){
  Map map = commonConfJdbcDao.getFtpConfig(modId);
  if(map == null || map.size() < 1){
   return false;
  }
  String ip = map.get("ip") == null ? "" : map.get("ip").toString();
  String account = map.get("account") == null ? "" : map.get("account").toString();
  String password = map.get("password") == null ? "" : map.get("password").toString();
  String path_root = map.get("path_root") == null ? "" : map.get("path_root").toString();
  
  
  if( "".equals(ip) || "".equals(account) || "".equals(password)){
   return false;
  }
  try{
   ApacheFtpUtil ftp = ApacheFtpUtil.getInstance(ip, 21, account, password);
   if(!ftp.isPositive()){
    return false;
   }
   ftp.recursionDele(path_root + "/" + fileName);
  }catch(Exception e){
   e.printStackTrace();
   return false;
  }
  
  
  return true;
 }
0 0
原创粉丝点击