- 上传指定文件夹到ftp服务器上
- public String uploadFolder(String folderName, String ftpPath)
- throws Exception {
- if (isLogin) {
- String strMsg = "";
- try {
- File file = new File(folderName);
- if (file.isDirectory()) {
- ftpClient.chdir("/");
- ftpClient.setType(FTPTransferType.BINARY);
- if (checkFolderIsExist(ftpPath)) {
- ftpClient.chdir(ftpPath);
- } else {
- createFolder(ftpPath);
- }
- if (!checkFolderIsExist(file.getName())) {
- ftpClient.mkdir(file.getName());
- }
- ftpClient.chdir(file.getName());
- ftpPath = ftpPath + "" + file.getName();
- File[] files = file.listFiles();
- for (int i = 0; i < files.length; i++) {
- if (files[i].isDirectory()) {
- uploadFolder(files[i].getPath(), ftpPath);
- } else {
- if (files[i].isFile()) {
- try {
- ftpClient.put(files[i].getPath(), files[i]
- .getName());
- } catch (Exception ee) {
- strMsg += "upload file<<:"
- + files[i].getPath()
- + ">> error!Message:"
- + ee.getMessage() + "rn";
- }
- }
- }
- }
- if (!strMsg.equals("")) {
- throw new Exception(strMsg);
- }
- } else {
- throw new Exception(folderName + " is not a folder'name!");
- }
- } catch (Exception e) {
- strMsg += e.getMessage() + "rn";
- }
- return strMsg;
- } else {
- throw new Exception("you didnot login remote ftp server!");
- }
- }
上传指定文件夹到ftp服务器上
最新推荐文章于 2023-07-08 16:11:12 发布