Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
ftp_proxy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李辅翼
ftp_proxy
Commits
b4ac4eae
Commit
b4ac4eae
authored
Dec 16, 2019
by
李辅翼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix it
parent
c9f96191
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
145 additions
and
0 deletions
+145
-0
src/main/java/com/hikcreate/ftp/proxy/modules/ftp/api/FtpProxyWebApi.java
+145
-0
No files found.
src/main/java/com/hikcreate/ftp/proxy/modules/ftp/api/FtpProxyWebApi.java
View file @
b4ac4eae
...
@@ -87,6 +87,12 @@ public class FtpProxyWebApi {
...
@@ -87,6 +87,12 @@ public class FtpProxyWebApi {
}
}
}
}
/**
* ftp
*
* @param urls
* @return
*/
@PostMapping
(
"/testFtpUtil"
)
@PostMapping
(
"/testFtpUtil"
)
public
synchronized
PicByte
testFtpUtil
(
@RequestParam
(
"urls"
)
String
urls
)
{
public
synchronized
PicByte
testFtpUtil
(
@RequestParam
(
"urls"
)
String
urls
)
{
PicByte
picByte
=
new
PicByte
();
PicByte
picByte
=
new
PicByte
();
...
@@ -155,6 +161,13 @@ public class FtpProxyWebApi {
...
@@ -155,6 +161,13 @@ public class FtpProxyWebApi {
}
}
}
}
/**
* http
*
* @param urls
* @return
*/
@PostMapping
(
"/testHttpUtil"
)
@PostMapping
(
"/testHttpUtil"
)
public
synchronized
PicByte
testHttpUtil
(
@RequestParam
(
"urls"
)
String
urls
)
{
public
synchronized
PicByte
testHttpUtil
(
@RequestParam
(
"urls"
)
String
urls
)
{
String
[]
urlArr
=
urls
.
split
(
","
);
String
[]
urlArr
=
urls
.
split
(
","
);
...
@@ -226,6 +239,138 @@ public class FtpProxyWebApi {
...
@@ -226,6 +239,138 @@ public class FtpProxyWebApi {
}
}
/**
* ftp总队的
*
* @param url
* @return
*/
@GetMapping
(
"/ftpPic"
)
public
void
ftpPic
(
@RequestParam
(
"url"
)
String
url
,
HttpServletResponse
response
)
{
FtpUtil
ftpUtil
=
null
;
byte
[]
bytes
=
null
;
try
{
paramUrl
(
url
);
ftpUtil
=
new
FtpUtil
(
host
,
21
,
userName
,
password
);
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
boolean
flag
=
ftpUtil
.
downloadPicFile
(
path
,
filename
,
bos
);
if
(
flag
)
{
bytes
=
bos
.
toByteArray
();
}
else
{
logger
.
info
(
"获取图片失败"
);
}
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
ftpUtil
!=
null
)
{
ftpUtil
=
null
;
}
}
try
{
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/octet-stream"
);
response
.
addHeader
(
"Content-Disposition"
,
"attachment; filename=\"test.jpg\""
);
response
.
getOutputStream
().
write
(
bytes
);
}
catch
(
IOException
e
)
{
}
}
/**
* http总队的
*
* @param urls
* @return
*/
@GetMapping
(
"/httpPic"
)
public
void
httpPic
(
@RequestParam
(
"url"
)
String
urls
,
HttpServletResponse
response
)
{
Map
<
String
,
byte
[]>
map
=
new
HashMap
<>();
HttpURLConnection
httpURLConnection
=
null
;
InputStream
inputStream
=
null
;
ByteArrayOutputStream
bos
=
null
;
byte
[]
buffer
=
null
;
try
{
URL
url
=
new
URL
(
urls
);
httpURLConnection
=
(
HttpURLConnection
)
url
.
openConnection
();
httpURLConnection
.
setConnectTimeout
(
3000
);
httpURLConnection
.
setDoInput
(
true
);
httpURLConnection
.
setRequestMethod
(
"GET"
);
int
responseCode
=
httpURLConnection
.
getResponseCode
();
if
(
responseCode
==
200
)
{
// 从服务器返回一个输入流
inputStream
=
httpURLConnection
.
getInputStream
();
if
(
inputStream
!=
null
&&
inputStream
.
available
()
>
0
)
{
bos
=
new
ByteArrayOutputStream
();
int
length
;
byte
[]
buf
=
new
byte
[
1024
*
2
];
while
(-
1
!=
(
length
=
inputStream
.
read
(
buf
,
0
,
buf
.
length
)))
{
bos
.
write
(
buf
,
0
,
length
);
}
ByteArrayInputStream
fis
=
new
ByteArrayInputStream
(
bos
.
toByteArray
());
bos
.
flush
();
bos
.
close
();
buffer
=
new
byte
[
fis
.
available
()];
int
offset
=
0
;
int
numRead
=
0
;
while
(
offset
<
buffer
.
length
&&
(
numRead
=
fis
.
read
(
buffer
,
offset
,
buffer
.
length
-
offset
))
>=
0
)
{
offset
+=
numRead
;
}
if
(
offset
!=
buffer
.
length
)
{
throw
new
IOException
(
"Could not completely read file "
);
}
fis
.
close
();
}
inputStream
.
close
();
}
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
inputStream
!=
null
)
{
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
bos
!=
null
)
{
try
{
bos
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
try
{
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/octet-stream"
);
response
.
addHeader
(
"Content-Disposition"
,
"attachment; filename=\"test.jpg\""
);
response
.
getOutputStream
().
write
(
buffer
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
/**
* http总队的
*
* @param
* @return
*/
@GetMapping
(
"/showImg"
)
public
void
showImg
(
@RequestParam
(
"url"
)
String
urls
,
HttpServletResponse
response
)
{
try
{
String
html
=
"<html><body><img src=\"/ftp/httpPic?url="
+
urls
+
"\"/></body></html>"
;
response
.
getOutputStream
().
write
(
html
.
getBytes
(
"UTF-8"
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@PostMapping
(
"/downloadByUrls"
)
@PostMapping
(
"/downloadByUrls"
)
public
synchronized
PicByte
list2
(
@RequestParam
(
"urls"
)
String
urls
,
HttpServletResponse
response
)
{
public
synchronized
PicByte
list2
(
@RequestParam
(
"urls"
)
String
urls
,
HttpServletResponse
response
)
{
PicByte
picByte
=
new
PicByte
();
PicByte
picByte
=
new
PicByte
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment