Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
71cbfc09
提交
71cbfc09
authored
16 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve FTP client.
上级
3792b52f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
26 行增加
和
10 行删除
+26
-10
FtpClient.java
h2/src/tools/org/h2/dev/ftp/FtpClient.java
+26
-10
没有找到文件。
h2/src/tools/org/h2/dev/ftp/FtpClient.java
浏览文件 @
71cbfc09
...
...
@@ -76,20 +76,24 @@ public class FtpClient {
message
=
message
.
substring
(
idx
+
1
);
}
}
if
(
message
.
equals
(
"Quotas off"
))
{
continue
;
}
break
;
}
}
private
void
readCode
(
int
expected
)
throws
IOException
{
private
void
readCode
(
int
optional
,
int
expected
)
throws
IOException
{
readLine
();
if
(
code
==
optional
)
{
readLine
();
}
if
(
code
!=
expected
)
{
throw
new
IOException
(
"Expected: "
+
expected
+
" got: "
+
message
);
throw
new
IOException
(
"Expected: "
+
expected
+
" got: "
+
code
+
" "
+
message
);
}
}
private
void
readCode
(
int
expected
)
throws
IOException
{
readCode
(-
1
,
expected
);
}
private
void
send
(
String
command
)
{
writer
.
println
(
command
);
writer
.
flush
();
...
...
@@ -152,7 +156,7 @@ public class FtpClient {
*/
void
delete
(
String
fileName
)
throws
IOException
{
send
(
"DELE "
+
fileName
);
readCode
(
250
);
readCode
(
2
26
,
2
50
);
}
/**
...
...
@@ -162,7 +166,7 @@ public class FtpClient {
*/
public
void
makeDirectory
(
String
dir
)
throws
IOException
{
send
(
"MKD "
+
dir
);
readCode
(
257
);
readCode
(
2
26
,
2
57
);
}
/**
...
...
@@ -220,7 +224,7 @@ public class FtpClient {
private
void
passive
()
throws
IOException
{
send
(
"PASV"
);
readCode
(
227
);
readCode
(
22
6
,
22
7
);
int
first
=
message
.
indexOf
(
'('
)
+
1
;
int
last
=
message
.
indexOf
(
')'
);
String
[]
address
=
StringUtils
.
arraySplit
(
message
.
substring
(
first
,
last
),
','
,
true
);
...
...
@@ -252,6 +256,18 @@ public class FtpClient {
readCode
(
250
);
}
/**
* Read a file.
*
* @param fileName the file name
* @return the content, null if the file doesn't exist
*/
public
byte
[]
retrieve
(
String
fileName
)
throws
IOException
{
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
retrieve
(
fileName
,
buff
,
0
);
return
buff
.
toByteArray
();
}
/**
* Read a file ([REST] RETR).
*
...
...
@@ -267,7 +283,7 @@ public class FtpClient {
}
send
(
"RETR "
+
fileName
);
IOUtils
.
copyAndClose
(
inData
,
out
);
readCode
(
226
);
readCode
(
150
,
226
);
}
/**
...
...
@@ -277,7 +293,7 @@ public class FtpClient {
*/
public
void
removeDirectory
(
String
dir
)
throws
IOException
{
send
(
"RMD "
+
dir
);
readCode
(
250
);
readCode
(
2
26
,
2
50
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论