Class FtpServer

  • All Implemented Interfaces:
    Service

    public class FtpServer
    extends Tool
    implements Service
    Small FTP Server. Intended for ad-hoc networks in a secure environment. Remote connections are possible. See also https://cr.yp.to/ftp.html http://www.ftpguide.com/
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_PORT
      The default port to use for the FTP server.
      static java.lang.String DEFAULT_READ
      The default user name that is allowed to read data.
      static java.lang.String DEFAULT_ROOT
      The default root directory name used by the FTP server.
      static java.lang.String DEFAULT_WRITE
      The default user name that is allowed to read and write data.
      static java.lang.String DEFAULT_WRITE_PASSWORD
      The default password of the user that is allowed to read and write data.
      • Fields inherited from class org.h2.util.Tool

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      FtpServer()  
    • Field Detail

      • DEFAULT_PORT

        public static final int DEFAULT_PORT
        The default port to use for the FTP server. This value is also in the documentation and in the Server javadoc.
        See Also:
        Constant Field Values
      • DEFAULT_ROOT

        public static final java.lang.String DEFAULT_ROOT
        The default root directory name used by the FTP server. This value is also in the documentation and in the Server javadoc.
        See Also:
        Constant Field Values
      • DEFAULT_READ

        public static final java.lang.String DEFAULT_READ
        The default user name that is allowed to read data. This value is also in the documentation and in the Server javadoc.
        See Also:
        Constant Field Values
      • DEFAULT_WRITE

        public static final java.lang.String DEFAULT_WRITE
        The default user name that is allowed to read and write data. This value is also in the documentation and in the Server javadoc.
        See Also:
        Constant Field Values
      • DEFAULT_WRITE_PASSWORD

        public static final java.lang.String DEFAULT_WRITE_PASSWORD
        The default password of the user that is allowed to read and write data. This value is also in the documentation and in the Server javadoc.
        See Also:
        Constant Field Values
    • Constructor Detail

      • FtpServer

        public FtpServer()
    • Method Detail

      • main

        public static void main​(java.lang.String... args)
                         throws java.sql.SQLException
        When running without options, -tcp, -web, -browser, and -pg are started. Options are case sensitive.
        Supported options
        [-help] or [-?] Print the list of options
        [-web] Start the web server with the H2 Console
        [-webAllowOthers] Allow other computers to connect
        [-webPort <port>] The port (default: 8082)
        [-webSSL] Use encrypted (HTTPS) connections
        [-browser] Start a browser and open a page to login to the web server
        [-tcp] Start the TCP server
        [-tcpAllowOthers] Allow other computers to connect
        [-tcpPort <port>] The port (default: 9092)
        [-tcpSSL] Use encrypted (SSL) connections
        [-tcpPassword <pwd>] The password for shutting down a TCP server
        [-tcpShutdown "<url>"] Stop the TCP server; example: tcp://localhost:9094
        [-tcpShutdownForce] Do not wait until all connections are closed
        [-pg] Start the PG server
        [-pgAllowOthers] Allow other computers to connect
        [-pgPort <port>] The port (default: 5435)
        [-ftp] Start the FTP server
        [-ftpPort <port>] The port (default: 8021)
        [-ftpDir <dir>] The base directory (default: ftp)
        [-ftpRead <user>] The user name for reading (default: guest)
        [-ftpWrite <user>] The user name for writing (default: sa)
        [-ftpWritePassword <p>] The write password (default: sa)
        [-baseDir <dir>] The base directory for H2 databases; for all servers
        [-ifExists] Only existing databases may be opened; for all servers
        [-trace] Print additional trace information; for all servers
        Parameters:
        args - the command line arguments
        Throws:
        java.sql.SQLException
      • runTool

        public void runTool​(java.lang.String... args)
                     throws java.sql.SQLException
        Description copied from class: Tool
        Run the tool with the given output stream and arguments.
        Specified by:
        runTool in class Tool
        Parameters:
        args - the argument list
        Throws:
        java.sql.SQLException - on failure
      • listen

        public void listen()
        Description copied from interface: Service
        Listen for incoming connections. This method blocks.
        Specified by:
        listen in interface Service
      • init

        public void init​(java.lang.String... args)
        Description copied from interface: Service
        Initialize the service from command line options.
        Specified by:
        init in interface Service
        Parameters:
        args - the command line options
      • getURL

        public java.lang.String getURL()
        Description copied from interface: Service
        Get the URL of this service in a human readable form
        Specified by:
        getURL in interface Service
        Returns:
        the url
      • getPort

        public int getPort()
        Description copied from interface: Service
        Gets the port this service is listening on.
        Specified by:
        getPort in interface Service
        Returns:
        the port
      • start

        public void start()
        Description copied from interface: Service
        Start the service. This usually means create the server socket. This method must not block.
        Specified by:
        start in interface Service
      • stop

        public void stop()
        Description copied from interface: Service
        Stop the service.
        Specified by:
        stop in interface Service
      • isRunning

        public boolean isRunning​(boolean traceError)
        Description copied from interface: Service
        Check if the service is running.
        Specified by:
        isRunning in interface Service
        Parameters:
        traceError - if errors should be written
        Returns:
        if the server is running
      • getAllowOthers

        public boolean getAllowOthers()
        Description copied from interface: Service
        Check if remote connections are allowed.
        Specified by:
        getAllowOthers in interface Service
        Returns:
        true if remote connections are allowed
      • getType

        public java.lang.String getType()
        Description copied from interface: Service
        Get the human readable short name of the service.
        Specified by:
        getType in interface Service
        Returns:
        the type
      • getName

        public java.lang.String getName()
        Description copied from interface: Service
        Get the human readable name of the service.
        Specified by:
        getName in interface Service
        Returns:
        the name
      • setEventListener

        public void setEventListener​(FtpEventListener eventListener)
        Set the event listener. Only one listener can be registered.
        Parameters:
        eventListener - the new listener, or null to de-register
      • createFtpServer

        public static Server createFtpServer​(java.lang.String... args)
                                      throws java.sql.SQLException
        Create a new FTP server, but does not start it yet. Example:
         Server server = FtpServer.createFtpServer(null).start();
         
        Parameters:
        args - the argument list
        Returns:
        the server
        Throws:
        java.sql.SQLException
      • isDaemon

        public boolean isDaemon()
        Description copied from interface: Service
        Check if a daemon thread should be used.
        Specified by:
        isDaemon in interface Service
        Returns:
        true if a daemon thread should be used