|
@@ -68,7 +68,7 @@ public class SftpClientUtil {
|
|
|
if (!dir.exists()) {
|
|
|
dir.mkdirs();
|
|
|
}
|
|
|
- String filePath = path +"/" + UUID.randomUUID().toString().replaceAll("-", "") + file.getName();
|
|
|
+ String filePath = path +"/" + System.currentTimeMillis() + file.getName();
|
|
|
//File转MultipartFile文件
|
|
|
MultipartFile multipartFile = transformFile(file);
|
|
|
//保存文件
|
|
@@ -94,7 +94,7 @@ public class SftpClientUtil {
|
|
|
sftp.cd(remoteFolder);
|
|
|
}catch (SftpException e){
|
|
|
}
|
|
|
- String remoteName = UUID.randomUUID().toString().replaceAll("-", "") + remoteFileName;
|
|
|
+ String remoteName = System.currentTimeMillis() + remoteFileName;
|
|
|
sftp.put(fileStream, remoteName);
|
|
|
disconnect(sftp);
|
|
|
logger.info("文件上传成功!! 耗时:{"+(System.currentTimeMillis() - start)+"}ms");
|
|
@@ -261,7 +261,7 @@ public class SftpClientUtil {
|
|
|
//将文件读入文件流
|
|
|
InputStream inStream = new FileInputStream(fileurl);
|
|
|
//判断浏览器代理并分别设置响应给浏览器的编码格式(并去除文件服务器中文件的UUID头展示信息)
|
|
|
- String finalFileName = URLEncoder.encode(downloadFile.substring(32, downloadFile.length()),"UTF8");
|
|
|
+ String finalFileName = URLEncoder.encode(downloadFile.substring(13, downloadFile.length()),"UTF8");
|
|
|
//设置HTTP响应头
|
|
|
response.reset();//重置 响应头
|
|
|
response.setContentType("application/x-download");//告知浏览器下载文件,而不是直接打开,浏览器默认为打开
|
|
@@ -280,7 +280,7 @@ public class SftpClientUtil {
|
|
|
if(path != null && !"".equals(path)){
|
|
|
sftp.cd(path);
|
|
|
}
|
|
|
- String fileName = URLEncoder.encode(downloadFile.substring(32, downloadFile.length()),"UTF-8");
|
|
|
+ String fileName = URLEncoder.encode(downloadFile.substring(13, downloadFile.length()),"UTF-8");
|
|
|
OutputStream out = null;
|
|
|
InputStream in = sftp.get(downloadFile);
|
|
|
response.reset();//重置 响应头
|
|
@@ -308,25 +308,13 @@ public class SftpClientUtil {
|
|
|
*
|
|
|
* @param directory SFTP服务器的文件路径
|
|
|
* @param downloadFile SFTP服务器上的文件名
|
|
|
- * @param downLoadFilePath 保存路径
|
|
|
- * @param finalFileName 准备生成的文件名
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
+ * @return 字节数组
|
|
|
*/
|
|
|
public byte[] downloadRuralProject(String directory, String downloadFile,String downLoadFilePath,String finalFileName) throws IOException {
|
|
|
File dirFile = new File(downLoadFilePath);
|
|
|
if (!dirFile.exists()) {
|
|
|
dirFile.mkdirs();
|
|
|
}
|
|
|
- //睡眠1毫秒 用来防止相同文件名被替换
|
|
|
- try {
|
|
|
- Thread.sleep(1);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- //文件名处理(将文件名拆分为名称和后缀名为之后添加时间戳做准备)
|
|
|
- String headName = finalFileName.substring(0,finalFileName.lastIndexOf("."));
|
|
|
- String endName = finalFileName.substring(finalFileName.lastIndexOf("."),finalFileName.length());
|
|
|
if("1".equals(uploadMode)){
|
|
|
OutputStream out = null;
|
|
|
InputStream in = null;
|
|
@@ -345,7 +333,7 @@ public class SftpClientUtil {
|
|
|
downLoadFilePath += "/";
|
|
|
}
|
|
|
//写入到文件(注意文件保存路径的后面一定要加上文件的名称)
|
|
|
- fileOut = new FileOutputStream(downLoadFilePath + headName + System.currentTimeMillis() + endName);
|
|
|
+ fileOut = new FileOutputStream(downLoadFilePath + downloadFile);
|
|
|
BufferedOutputStream bos = new BufferedOutputStream(fileOut);
|
|
|
byte[] buf = new byte[4096];
|
|
|
int length = bis.read(buf);
|
|
@@ -376,7 +364,7 @@ public class SftpClientUtil {
|
|
|
//将文件读入文件流
|
|
|
InputStream inStream = new FileInputStream(fileurl);
|
|
|
|
|
|
- File file = new File(downLoadFilePath,headName + System.currentTimeMillis() + endName);
|
|
|
+ File file = new File(downLoadFilePath,downloadFile);
|
|
|
//将下载保存到文件。
|
|
|
FileOutputStream out = new FileOutputStream(file);
|
|
|
Streams.copy(inStream, out, true);
|
|
@@ -389,7 +377,7 @@ public class SftpClientUtil {
|
|
|
|
|
|
BufferedInputStream bis = new BufferedInputStream(inputStream);
|
|
|
//写入到文件(注意文件保存路径的后面一定要加上文件的名称)
|
|
|
- FileOutputStream fileOut = new FileOutputStream(downLoadFilePath + "/" + headName + System.currentTimeMillis() + endName);
|
|
|
+ FileOutputStream fileOut = new FileOutputStream(downLoadFilePath + "/" + downloadFile);
|
|
|
BufferedOutputStream bos = new BufferedOutputStream(fileOut);
|
|
|
|
|
|
byte[] buf = new byte[4096];
|