提交 1abde6ed authored 作者: Thomas Mueller's avatar Thomas Mueller

The FTP server moved to the tools section.

上级 d6383f94
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Improved error message for unsupported features:
<ul><li>The FTP server moved to the tools section and is no longer included in the h2*.jar file.
</li><li>Improved error message for unsupported features:
now the message says what exactly is not supported.
</li><li>Improved OSGi support.
</li><li>Some internal caches did not use the LRU mechanism. Fixed
......
......@@ -16,27 +16,32 @@ import org.h2.message.TraceSystem;
import org.h2.server.Service;
import org.h2.server.ShutdownHandler;
import org.h2.server.TcpServer;
import org.h2.server.ftp.FtpServer;
import org.h2.server.pg.PgServer;
import org.h2.server.web.WebServer;
import org.h2.util.StartBrowser;
import org.h2.util.Tool;
/**
* Starts the H2 Console (web-) server, TCP, PG, and FTP server.
* Starts the H2 Console (web-) server, TCP, and PG server.
* @h2.resource
*/
public class Server extends Tool implements Runnable, ShutdownHandler {
private Service service;
private Server web, tcp, pg, ftp;
private Server web, tcp, pg;
private ShutdownHandler shutdownHandler;
public Server() {
// nothing to do
}
private Server(Service service, String[] args) throws SQLException {
/**
* Create a new server for the given service.
*
* @param service the service
* @param args the command line arguments
*/
public Server(Service service, String[] args) throws SQLException {
this.service = service;
try {
service.init(args);
......@@ -46,7 +51,8 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
}
/**
* When running without options, -tcp, -web, -browser and -pg are started.<br />
* When running without options, -tcp, -web, -browser and -pg are started.
* <br />
* Options are case sensitive. Supported options are:
* <table>
* <tr><td>[-help] or [-?]</td>
......@@ -81,18 +87,6 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* <td>Allow other computers to connect</td></tr>
* <tr><td>[-pgPort &lt;port&gt;]</td>
* <td>The port (default: 5435)</td></tr>
* <tr><td>[-ftp]</td>
* <td>Start the FTP server</td></tr>
* <tr><td>[-ftpPort &lt;port&gt;]</td>
* <td>The port (default: 8021)</td></tr>
* <tr><td>[-ftpDir &lt;dir&gt;]</td>
* <td>The base directory (default: ftp)</td></tr>
* <tr><td>[-ftpRead &lt;user&gt;]</td>
* <td>The user name for reading (default: guest)</td></tr>
* <tr><td>[-ftpWrite &lt;user&gt;]</td>
* <td>The user name for writing (default: sa)</td></tr>
* <tr><td>[-ftpWritePassword &lt;p&gt;]</td>
* <td>The write password (default: sa)</td></tr>
* <tr><td>[-baseDir &lt;dir&gt;]</td>
* <td>The base directory for H2 databases; for all servers</td></tr>
* <tr><td>[-ifExists]</td>
......@@ -109,7 +103,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
}
public void run(String[] args) throws SQLException {
boolean tcpStart = false, pgStart = false, webStart = false, ftpStart = false;
boolean tcpStart = false, pgStart = false, webStart = false;
boolean browserStart = false;
boolean tcpShutdown = false, tcpShutdownForce = false;
String tcpPassword = "";
......@@ -187,25 +181,6 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
} else {
throwUnsupportedOption(arg);
}
} else if (arg.startsWith("-ftp")) {
if ("-ftp".equals(arg)) {
startDefaultServers = false;
ftpStart = true;
} else if ("-ftpPort".equals(arg)) {
i++;
} else if ("-ftpDir".equals(arg)) {
i++;
} else if ("-ftpRead".equals(arg)) {
i++;
} else if ("-ftpWrite".equals(arg)) {
i++;
} else if ("-ftpWritePassword".equals(arg)) {
i++;
} else if ("-ftpTask".equals(arg)) {
// no parameters
} else {
throwUnsupportedOption(arg);
}
} else if ("-trace".equals(arg)) {
// no parameters
} else if ("-log".equals(arg) && SysProperties.OLD_COMMAND_LINE_OPTIONS) {
......@@ -261,11 +236,6 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
pg.start();
out.println(pg.getStatus());
}
if (ftpStart) {
ftp = createFtpServer(args);
ftp.start();
out.println(ftp.getStatus());
}
}
/**
......@@ -290,7 +260,12 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
TcpServer.shutdown(url, password, force);
}
String getStatus() {
/**
* Get the status of this server.
*
* @return the status
*/
public String getStatus() {
StringBuffer buff = new StringBuffer();
if (isRunning(false)) {
buff.append(service.getType());
......@@ -328,21 +303,6 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
return server;
}
/**
* Create a new ftp server, but does not start it yet. Example:
*
* <pre>
* Server server = Server.createFtpServer(
* new String[] { &quot;-trace&quot; }).start();
* </pre>
*
* @param args the argument list
* @return the server
*/
public static Server createFtpServer(String[] args) throws SQLException {
return new Server(new FtpServer(), args);
}
/**
* Create a new TCP server, but does not start it yet. Example:
*
......@@ -420,10 +380,6 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
pg.stop();
pg = null;
}
if (ftp != null && ftp.isRunning(false)) {
ftp.stop();
ftp = null;
}
}
/**
......
......@@ -33,7 +33,7 @@ public class TestFtp extends TestBase implements FtpEventListener {
}
private void test(String dir) throws Exception {
Server server = Server.createFtpServer(new String[]{"-ftpDir", dir, "-ftpPort", "8121"}).start();
Server server = FtpServer.createFtpServer(new String[]{"-ftpDir", dir, "-ftpPort", "8121"}).start();
FtpServer ftp = (FtpServer) server.getService();
ftp.setEventListener(this);
FtpClient client = FtpClient.open("localhost:8121");
......
......@@ -241,6 +241,7 @@ public class Build extends BuildBase {
exclude("temp/org/h2/jaqu/*").
exclude("temp/org/h2/mode/*").
exclude("temp/org/h2/samples/*").
exclude("temp/org/h2/server/ftp/*").
exclude("temp/org/h2/test/*").
exclude("*.bat").
exclude("*.sh").
......
......@@ -18,10 +18,10 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Properties;
import org.h2.constant.SysProperties;
import org.h2.server.Service;
import org.h2.store.fs.FileSystem;
import org.h2.tools.Server;
import org.h2.util.FileUtils;
import org.h2.util.IOUtils;
import org.h2.util.MathUtils;
......@@ -34,7 +34,7 @@ import org.h2.util.Tool;
* Remote connections are possible.
* See also http://cr.yp.to/ftp.html http://www.ftpguide.com/
*/
public class FtpServer implements Service {
public class FtpServer extends Tool implements Service {
/**
* The default port to use for the FTP server.
......@@ -88,6 +88,105 @@ public class FtpServer implements Service {
private FtpEventListener eventListener;
/**
* When running without options, -tcp, -web, -browser and -pg are started.<br />
* Options are case sensitive. Supported options are:
* <table>
* <tr><td>[-help] or [-?]</td>
* <td>Print the list of options</td></tr>
* <tr><td>[-web]</td>
* <td>Start the web server with the H2 Console</td></tr>
* <tr><td>[-webAllowOthers]</td>
* <td>Allow other computers to connect</td></tr>
* <tr><td>[-webPort &lt;port&gt;]</td>
* <td>The port (default: 8082)</td></tr>
* <tr><td>[-webSSL]</td>
* <td>Use encrypted (HTTPS) connections</td></tr>
* <tr><td>[-browser]</td>
* <td>Start a browser and open a page to connect to the web server</td></tr>
* <tr><td>[-tcp]</td>
* <td>Start the TCP server</td></tr>
* <tr><td>[-tcpAllowOthers]</td>
* <td>Allow other computers to connect</td></tr>
* <tr><td>[-tcpPort &lt;port&gt;]</td>
* <td>The port (default: 9092)</td></tr>
* <tr><td>[-tcpSSL]</td>
* <td>Use encrypted (SSL) connections</td></tr>
* <tr><td>[-tcpPassword &lt;pwd&gt;]</td>
* <td>The password for shutting down a TCP server</td></tr>
* <tr><td>[-tcpShutdown &lt;url&gt;]</td>
* <td>Stop the TCP server; example: tcp://localhost:9094</td></tr>
* <tr><td>[-tcpShutdownForce]</td>
* <td>Do not wait until all connections are closed</td></tr>
* <tr><td>[-pg]</td>
* <td>Start the PG server</td></tr>
* <tr><td>[-pgAllowOthers]</td>
* <td>Allow other computers to connect</td></tr>
* <tr><td>[-pgPort &lt;port&gt;]</td>
* <td>The port (default: 5435)</td></tr>
* <tr><td>[-ftp]</td>
* <td>Start the FTP server</td></tr>
* <tr><td>[-ftpPort &lt;port&gt;]</td>
* <td>The port (default: 8021)</td></tr>
* <tr><td>[-ftpDir &lt;dir&gt;]</td>
* <td>The base directory (default: ftp)</td></tr>
* <tr><td>[-ftpRead &lt;user&gt;]</td>
* <td>The user name for reading (default: guest)</td></tr>
* <tr><td>[-ftpWrite &lt;user&gt;]</td>
* <td>The user name for writing (default: sa)</td></tr>
* <tr><td>[-ftpWritePassword &lt;p&gt;]</td>
* <td>The write password (default: sa)</td></tr>
* <tr><td>[-baseDir &lt;dir&gt;]</td>
* <td>The base directory for H2 databases; for all servers</td></tr>
* <tr><td>[-ifExists]</td>
* <td>Only existing databases may be opened; for all servers</td></tr>
* <tr><td>[-trace]</td>
* <td>Print additional trace information; for all servers</td></tr>
* </table>
* @h2.resource
*
* @param args the command line arguments
*/
public static void main(String[] args) throws SQLException {
new FtpServer().run(args);
}
public void run(String[] args) throws SQLException {
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg == null) {
continue;
} else if ("-?".equals(arg) || "-help".equals(arg)) {
showUsage();
return;
} else if (arg.startsWith("-ftp")) {
if ("-ftpPort".equals(arg)) {
i++;
} else if ("-ftpDir".equals(arg)) {
i++;
} else if ("-ftpRead".equals(arg)) {
i++;
} else if ("-ftpWrite".equals(arg)) {
i++;
} else if ("-ftpWritePassword".equals(arg)) {
i++;
} else if ("-ftpTask".equals(arg)) {
// no parameters
} else {
throwUnsupportedOption(arg);
}
} else if ("-trace".equals(arg)) {
// no parameters
} else {
throwUnsupportedOption(arg);
}
}
Server server = new Server(this, args);
server.start();
out.println(server.getStatus());
}
public void listen() {
try {
while (serverSocket != null) {
......@@ -448,4 +547,18 @@ public class FtpServer implements Service {
return eventListener;
}
/**
* Create a new FTP server, but does not start it yet. Example:
*
* <pre>
* Server server = FtpServer.createFtpServer(null).start();
* </pre>
*
* @param args the argument list
* @return the server
*/
public static Server createFtpServer(String[] args) throws SQLException {
return new Server(new FtpServer(), args);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论