提交 67f77d9e authored 作者: lizhuo's avatar lizhuo

--no commit message

上级 9780954e
...@@ -8,6 +8,7 @@ import java.io.FileNotFoundException; ...@@ -8,6 +8,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
...@@ -166,10 +167,12 @@ public class FTPController { ...@@ -166,10 +167,12 @@ public class FTPController {
* 下载到当地那个路径下 * 下载到当地那个路径下
* @param remoteDownLoadPath * @param remoteDownLoadPath
* remoteFileName所在的路径 * remoteFileName所在的路径
* @throws Exception
*/ */
@ApiOperation(value = "文件下载") @ApiOperation(value = "文件下载")
@RequestMapping(value = "/download/file", method = RequestMethod.GET) @RequestMapping(value = "/download/file", method = RequestMethod.GET)
public boolean downloadFile(String remoteFileName, String localDires, String remoteDownLoadPath) { public boolean downloadFile(String remoteFileName, String localDires, String remoteDownLoadPath,HttpServletRequest request) throws Exception {
request.setCharacterEncoding("UTF-8");
this.ftpLogin(); this.ftpLogin();
String strFilePath = localDires + remoteFileName; String strFilePath = localDires + remoteFileName;
BufferedOutputStream outStream = null; BufferedOutputStream outStream = null;
...@@ -211,14 +214,14 @@ public class FTPController { ...@@ -211,14 +214,14 @@ public class FTPController {
*/ */
@ApiOperation(value = "文件夹下载") @ApiOperation(value = "文件夹下载")
@RequestMapping(value = "/download/directory", method = RequestMethod.GET) @RequestMapping(value = "/download/directory", method = RequestMethod.GET)
public boolean downLoadDirectory(String localDirectoryPath, String remoteDirectory) { public boolean downLoadDir(String localDirectoryPath, String remoteDirectory) throws Exception {
this.ftpLogin(); this.ftpLogin();
boolean mark = downloadDirectory(localDirectoryPath, remoteDirectory); boolean mark = downloadDirectory(localDirectoryPath, remoteDirectory);
this.ftpLogOut(); this.ftpLogOut();
return mark; return mark;
} }
public boolean downloadDirectory(String localDirectoryPath, String remoteDirectory) { public boolean downloadDirectory(String localDirectoryPath, String remoteDirectory) throws Exception {
try { try {
String fileName = new File(remoteDirectory).getName(); String fileName = new File(remoteDirectory).getName();
localDirectoryPath = localDirectoryPath + "/" + fileName + "//"; localDirectoryPath = localDirectoryPath + "/" + fileName + "//";
...@@ -229,7 +232,7 @@ public class FTPController { ...@@ -229,7 +232,7 @@ public class FTPController {
downloadFile(file.getName(), localDirectoryPath, remoteDirectory); downloadFile(file.getName(), localDirectoryPath, remoteDirectory);
} else { } else {
String strremoteDirectoryPath = remoteDirectory + "/" + file.getName(); String strremoteDirectoryPath = remoteDirectory + "/" + file.getName();
downLoadDirectory(localDirectoryPath, strremoteDirectoryPath); downloadDirectory(localDirectoryPath, strremoteDirectoryPath);
} }
} }
} catch (IOException e) { } catch (IOException e) {
...@@ -237,6 +240,38 @@ public class FTPController { ...@@ -237,6 +240,38 @@ public class FTPController {
} }
return true; return true;
} }
public boolean downloadFile(String remoteFileName, String localDires, String remoteDownLoadPath) throws Exception {
String strFilePath = localDires + remoteFileName;
BufferedOutputStream outStream = null;
boolean success = false;
try {
this.ftpClient.changeWorkingDirectory(remoteDownLoadPath);
outStream = new BufferedOutputStream(new FileOutputStream(strFilePath));
logger.info(remoteFileName + "开始下载....");
success = this.ftpClient.retrieveFile(remoteFileName, outStream);
if (success == true) {
logger.info(remoteFileName + "成功下载到" + strFilePath);
return success;
}
} catch (Exception e) {
throw new BaseException(remoteFileName + "下载失败");
} finally {
if (null != outStream) {
try {
outStream.flush();
outStream.close();
} catch (IOException e) {
throw new BaseException("流关闭失败");
}
}
}
if (success == false) {
logger.error(remoteFileName + "下载失败!!!");
}
return success;
}
@ApiOperation(value = "查看列表") @ApiOperation(value = "查看列表")
@RequestMapping(value = "/list", method = RequestMethod.GET) @RequestMapping(value = "/list", method = RequestMethod.GET)
...@@ -354,35 +389,6 @@ public class FTPController { ...@@ -354,35 +389,6 @@ public class FTPController {
return success; return success;
} }
/***
* @上传文件夹
* @param localDirectory
* 当地文件夹
* @param remoteDirectoryPath
* Ftp 服务器路径 以目录"/"结束
*/
public boolean uploadDirectory(String localDirectory, String remoteDirectoryPath) {
this.ftpLogin();
File src = new File(localDirectory);
try {
remoteDirectoryPath = remoteDirectoryPath + src.getName() + "/";
this.ftpClient.makeDirectory(remoteDirectoryPath);
} catch (IOException e) {
e.printStackTrace();
logger.info(remoteDirectoryPath + "目录创建失败");
}
File[] allFile = src.listFiles();
for (File file : allFile) {
if (!file.isDirectory()) {
String srcName = file.getPath().toString();
uploadFile(new File(srcName), remoteDirectoryPath);
} else {
uploadDirectory(file.getPath().toString(), remoteDirectoryPath);
}
}
this.ftpLogOut();
return true;
}
/** /**
* 文件夹解析 * 文件夹解析
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论