Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
nrgl
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
注册表
注册表
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
svn
nrgl
Commits
67f77d9e
提交
67f77d9e
authored
2月 19, 2019
作者:
lizhuo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
上级
9780954e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
39 行增加
和
33 行删除
+39
-33
FTPController.java
...src/main/java/com/zrqx/file/controller/FTPController.java
+39
-33
没有找到文件。
com.zrqx.file/src/main/java/com/zrqx/file/controller/FTPController.java
浏览文件 @
67f77d9e
...
@@ -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
downLoadDir
ectory
(
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
();
down
L
oadDirectory
(
localDirectoryPath
,
strremoteDirectoryPath
);
down
l
oadDirectory
(
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论