上传指定文件夹到ftp服务器上

  1. 上传指定文件夹到ftp服务器上   
  2.     public String uploadFolder(String folderName, String ftpPath)   
  3.             throws Exception {   
  4.         if (isLogin) {   
  5.             String strMsg = "";   
  6.             try {   
  7.                 File file = new File(folderName);   
  8.                 if (file.isDirectory()) {   
  9.                     ftpClient.chdir("/");   
  10.                     ftpClient.setType(FTPTransferType.BINARY);   
  11.                     if (checkFolderIsExist(ftpPath)) {   
  12.                         ftpClient.chdir(ftpPath);   
  13.                     } else {   
  14.                         createFolder(ftpPath);   
  15.                     }   
  16.                     if (!checkFolderIsExist(file.getName())) {   
  17.                         ftpClient.mkdir(file.getName());   
  18.                     }   
  19.                     ftpClient.chdir(file.getName());   
  20.                     ftpPath = ftpPath + "" + file.getName();   
  21.                     File[] files = file.listFiles();   
  22.                     for (int i = 0; i < files.length; i++) {   
  23.                         if (files[i].isDirectory()) {   
  24.                             uploadFolder(files[i].getPath(), ftpPath);   
  25.                         } else {   
  26.                             if (files[i].isFile()) {   
  27.                                 try {   
  28.                                     ftpClient.put(files[i].getPath(), files[i]   
  29.                                             .getName());   
  30.                                 } catch (Exception ee) {   
  31.                                     strMsg += "upload file<<:"  
  32.                                             + files[i].getPath()   
  33.                                             + ">> error!Message:"  
  34.                                             + ee.getMessage() + "rn";   
  35.                                 }   
  36.                             }   
  37.                         }   
  38.                     }   
  39.                     if (!strMsg.equals("")) {   
  40.                         throw new Exception(strMsg);   
  41.                     }   
  42.                 } else {   
  43.                     throw new Exception(folderName + " is not a folder'name!");   
  44.                 }   
  45.             } catch (Exception e) {   
  46.                 strMsg += e.getMessage() + "rn";   
  47.             }   
  48.             return strMsg;   
  49.         } else {   
  50.             throw new Exception("you didnot login remote ftp server!");   
  51.         }   
  52.     }  
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值