Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5c0650a7
提交
5c0650a7
authored
16 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move FTP server and client to dev package
上级
bf724510
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
164 行增加
和
28 行删除
+164
-28
TestFtp.java
h2/src/test/org/h2/test/unit/TestFtp.java
+4
-3
FtpClient.java
h2/src/tools/org/h2/dev/ftp/FtpClient.java
+139
-19
package.html
h2/src/tools/org/h2/dev/ftp/package.html
+1
-1
FtpControl.java
h2/src/tools/org/h2/dev/ftp/server/FtpControl.java
+1
-1
FtpData.java
h2/src/tools/org/h2/dev/ftp/server/FtpData.java
+1
-1
FtpEvent.java
h2/src/tools/org/h2/dev/ftp/server/FtpEvent.java
+1
-1
FtpEventListener.java
h2/src/tools/org/h2/dev/ftp/server/FtpEventListener.java
+1
-1
FtpServer.java
h2/src/tools/org/h2/dev/ftp/server/FtpServer.java
+1
-1
package.html
h2/src/tools/org/h2/dev/ftp/server/package.html
+15
-0
没有找到文件。
h2/src/test/org/h2/test/unit/TestFtp.java
浏览文件 @
5c0650a7
...
...
@@ -6,9 +6,10 @@
*/
package
org
.
h2
.
test
.
unit
;
import
org.h2.server.ftp.FtpEvent
;
import
org.h2.server.ftp.FtpEventListener
;
import
org.h2.server.ftp.FtpServer
;
import
org.h2.dev.ftp.FtpClient
;
import
org.h2.dev.ftp.server.FtpEvent
;
import
org.h2.dev.ftp.server.FtpEventListener
;
import
org.h2.dev.ftp.server.FtpServer
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Server
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/t
est/org/h2/test/unit
/FtpClient.java
→
h2/src/t
ools/org/h2/dev/ftp
/FtpClient.java
浏览文件 @
5c0650a7
...
...
@@ -4,10 +4,12 @@
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
unit
;
package
org
.
h2
.
dev
.
ftp
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
...
...
@@ -45,7 +47,7 @@ public class FtpClient {
* @param url the FTP URL
* @return the ftp client object
*/
static
FtpClient
open
(
String
url
)
throws
IOException
{
public
static
FtpClient
open
(
String
url
)
throws
IOException
{
FtpClient
client
=
new
FtpClient
();
client
.
connect
(
url
);
return
client
;
...
...
@@ -61,9 +63,12 @@ public class FtpClient {
}
private
void
readLine
()
throws
IOException
{
while
(
true
)
{
message
=
reader
.
readLine
();
if
(
message
!=
null
)
{
int
idx
=
message
.
indexOf
(
' '
);
int
idxSpace
=
message
.
indexOf
(
' '
);
int
idxMinus
=
message
.
indexOf
(
'-'
);
int
idx
=
idxSpace
<
0
?
idxMinus
:
idxMinus
<
0
?
idxSpace
:
Math
.
min
(
idxSpace
,
idxMinus
);
if
(
idx
<
0
)
{
code
=
0
;
}
else
{
...
...
@@ -71,6 +76,11 @@ public class FtpClient {
message
=
message
.
substring
(
idx
+
1
);
}
}
if
(
message
.
equals
(
"Quotas off"
))
{
continue
;
}
break
;
}
}
private
void
readCode
(
int
expected
)
throws
IOException
{
...
...
@@ -91,7 +101,7 @@ public class FtpClient {
* @param userName the user name
* @param password the password
*/
void
login
(
String
userName
,
String
password
)
throws
IOException
{
public
void
login
(
String
userName
,
String
password
)
throws
IOException
{
send
(
"USER "
+
userName
);
readCode
(
331
);
send
(
"PASS "
+
password
);
...
...
@@ -109,7 +119,7 @@ public class FtpClient {
/**
* Close the connection (QUIT).
*/
void
close
()
throws
IOException
{
public
void
close
()
throws
IOException
{
if
(
socket
!=
null
)
{
send
(
"QUIT"
);
readCode
(
221
);
...
...
@@ -122,7 +132,7 @@ public class FtpClient {
*
* @param dir the new directory
*/
void
changeWorkingDirectory
(
String
dir
)
throws
IOException
{
public
void
changeWorkingDirectory
(
String
dir
)
throws
IOException
{
send
(
"CWD "
+
dir
);
readCode
(
250
);
}
...
...
@@ -130,7 +140,7 @@ public class FtpClient {
/**
* Change to the parent directory (CDUP).
*/
void
changeDirectoryUp
()
throws
IOException
{
public
void
changeDirectoryUp
()
throws
IOException
{
send
(
"CDUP"
);
readCode
(
250
);
}
...
...
@@ -150,7 +160,7 @@ public class FtpClient {
*
* @param dir the directory to create
*/
void
makeDirectory
(
String
dir
)
throws
IOException
{
public
void
makeDirectory
(
String
dir
)
throws
IOException
{
send
(
"MKD "
+
dir
);
readCode
(
257
);
}
...
...
@@ -265,11 +275,30 @@ public class FtpClient {
*
* @param dir the directory to remove
*/
void
removeDirectory
(
String
dir
)
throws
IOException
{
public
void
removeDirectory
(
String
dir
)
throws
IOException
{
send
(
"RMD "
+
dir
);
readCode
(
250
);
}
/**
* Remove all files and directory in a directory, and then delete the
* directory itself.
*
* @param dir the directory to remove
*/
public
void
removeDirectoryRecursive
(
String
dir
)
throws
IOException
{
File
[]
list
=
listFiles
(
dir
);
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
File
f
=
list
[
i
];
if
(
f
.
isDirectory
())
{
removeDirectoryRecursive
(
dir
+
"/"
+
f
.
getName
());
}
else
{
delete
(
dir
+
"/"
+
f
.
getName
());
}
}
removeDirectory
(
dir
);
}
/**
* Get the size of a file (SIZE).
*
...
...
@@ -289,7 +318,7 @@ public class FtpClient {
* @param fileName the file name
* @param in the input stream
*/
void
store
(
String
fileName
,
InputStream
in
)
throws
IOException
{
public
void
store
(
String
fileName
,
InputStream
in
)
throws
IOException
{
passive
();
send
(
"STOR "
+
fileName
);
readCode
(
150
);
...
...
@@ -297,13 +326,33 @@ public class FtpClient {
readCode
(
226
);
}
/**
* Copy a local file or directory to the FTP server, recursively.
*
* @param file the file to copy
*/
public
void
storeRecursive
(
File
file
)
throws
IOException
{
if
(
file
.
isDirectory
())
{
makeDirectory
(
file
.
getName
());
changeWorkingDirectory
(
file
.
getName
());
File
[]
list
=
file
.
listFiles
();
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
storeRecursive
(
list
[
i
]);
}
changeWorkingDirectory
(
".."
);
}
else
{
InputStream
in
=
new
FileInputStream
(
file
);
store
(
file
.
getName
(),
in
);
}
}
/**
* Get the directory listing (NLST).
*
* @param dir the directory
* @return the listing
*/
String
nameList
(
String
dir
)
throws
IOException
{
public
String
nameList
(
String
dir
)
throws
IOException
{
passive
();
send
(
"NLST "
+
dir
);
readCode
(
150
);
...
...
@@ -320,7 +369,7 @@ public class FtpClient {
* @param dir the directory
* @return the listing
*/
String
list
(
String
dir
)
throws
IOException
{
public
String
list
(
String
dir
)
throws
IOException
{
passive
();
send
(
"LIST "
+
dir
);
readCode
(
150
);
...
...
@@ -331,4 +380,75 @@ public class FtpClient {
return
new
String
(
data
);
}
/**
* A file on an FTP server.
*/
static
class
FtpFile
extends
File
{
private
final
boolean
dir
;
private
final
long
length
;
FtpFile
(
String
name
,
boolean
dir
,
long
length
)
{
super
(
name
);
this
.
dir
=
dir
;
this
.
length
=
length
;
}
public
long
length
()
{
return
length
;
}
public
boolean
isFile
()
{
return
!
dir
;
}
public
boolean
isDirectory
()
{
return
dir
;
}
public
boolean
exists
()
{
return
true
;
}
}
/**
* Check if a file exists on the FTP server.
*
* @param dir the directory
* @param name the directory or file name
* @return true if it exists
*/
public
boolean
exists
(
String
dir
,
String
name
)
throws
IOException
{
File
[]
list
=
listFiles
(
dir
);
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
if
(
list
[
i
].
getName
().
equals
(
name
))
{
return
true
;
}
}
return
false
;
}
/**
* List the files on the FTP server.
*
* @param dir the directory
* @return the list of files
*/
public
File
[]
listFiles
(
String
dir
)
throws
IOException
{
String
content
=
list
(
dir
);
String
[]
list
=
StringUtils
.
arraySplit
(
content
.
trim
(),
'\n'
,
true
);
File
[]
files
=
new
File
[
list
.
length
];
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
String
s
=
list
[
i
];
while
(
true
)
{
String
s2
=
StringUtils
.
replaceAll
(
s
,
" "
,
" "
);
if
(
s2
.
equals
(
s
))
{
break
;
}
s
=
s2
;
}
String
[]
tokens
=
StringUtils
.
arraySplit
(
s
,
' '
,
true
);
boolean
directory
=
tokens
[
0
].
charAt
(
0
)
==
'd'
;
long
length
=
Long
.
parseLong
(
tokens
[
4
]);
String
name
=
tokens
[
8
];
File
f
=
new
FtpFile
(
name
,
directory
,
length
);
files
[
i
]
=
f
;
}
return
files
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/
server
/ftp/package.html
→
h2/src/tools/org/h2/
dev
/ftp/package.html
浏览文件 @
5c0650a7
...
...
@@ -10,6 +10,6 @@ Initial Developer: H2 Group
Javadoc package documentation
</title></head><body
style=
"font: 9pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;"
>
Implementation of the TCP server
.
A simple FTP client
.
</body></html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/
server/ftp
/FtpControl.java
→
h2/src/tools/org/h2/
dev/ftp/server
/FtpControl.java
浏览文件 @
5c0650a7
...
...
@@ -4,7 +4,7 @@
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
server
.
ftp
;
package
org
.
h2
.
dev
.
ftp
.
server
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/
server/ftp
/FtpData.java
→
h2/src/tools/org/h2/
dev/ftp/server
/FtpData.java
浏览文件 @
5c0650a7
...
...
@@ -4,7 +4,7 @@
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
server
.
ftp
;
package
org
.
h2
.
dev
.
ftp
.
server
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/
server/ftp
/FtpEvent.java
→
h2/src/tools/org/h2/
dev/ftp/server
/FtpEvent.java
浏览文件 @
5c0650a7
...
...
@@ -4,7 +4,7 @@
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
server
.
ftp
;
package
org
.
h2
.
dev
.
ftp
.
server
;
/**
* Describes an FTP event. This class is used by the FtpEventListener.
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/
server/ftp
/FtpEventListener.java
→
h2/src/tools/org/h2/
dev/ftp/server
/FtpEventListener.java
浏览文件 @
5c0650a7
...
...
@@ -4,7 +4,7 @@
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
server
.
ftp
;
package
org
.
h2
.
dev
.
ftp
.
server
;
/**
* Event listener for the FTP Server.
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/
server/ftp
/FtpServer.java
→
h2/src/tools/org/h2/
dev/ftp/server
/FtpServer.java
浏览文件 @
5c0650a7
...
...
@@ -4,7 +4,7 @@
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
server
.
ftp
;
package
org
.
h2
.
dev
.
ftp
.
server
;
import
java.io.File
;
import
java.io.IOException
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/dev/ftp/server/package.html
0 → 100644
浏览文件 @
5c0650a7
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License, Version 1.0,
and under the Eclipse Public License, Version 1.0
(http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html
xmlns=
"http://www.w3.org/1999/xhtml"
lang=
"en"
xml:lang=
"en"
>
<head><meta
http-equiv=
"Content-Type"
content=
"text/html;charset=utf-8"
/><title>
Javadoc package documentation
</title></head><body
style=
"font: 9pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;"
>
A simple FTP server.
</body></html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论