View Javadoc
1   /*
2    * This file is part of Waarp Project (named also Waarp or GG).
3    *
4    *  Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5    *  tags. See the COPYRIGHT.txt in the distribution for a full listing of
6    * individual contributors.
7    *
8    *  All Waarp Project is free software: you can redistribute it and/or
9    * modify it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License, or (at your
11   * option) any later version.
12   *
13   * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License along with
18   * Waarp . If not, see <http://www.gnu.org/licenses/>.
19   */
20  package org.waarp.ftp.simpleimpl;
21  
22  import org.waarp.common.file.filesystembased.FilesystemBasedFileParameterImpl;
23  import org.waarp.common.logging.SysErrLogger;
24  import org.waarp.common.logging.WaarpLogger;
25  import org.waarp.common.logging.WaarpLoggerFactory;
26  import org.waarp.common.logging.WaarpSlf4JLoggerFactory;
27  import org.waarp.ftp.core.exception.FtpNoConnectionException;
28  import org.waarp.ftp.simpleimpl.config.FileBasedConfiguration;
29  import org.waarp.ftp.simpleimpl.control.SimpleBusinessHandler;
30  import org.waarp.ftp.simpleimpl.data.FileSystemBasedDataBusinessHandler;
31  
32  /**
33   * Example of FTP Server using simple authentication (XML FileInterface based),
34   * and standard Directory and
35   * FileInterface implementation (Filesystem based).
36   */
37  public class SimpleGatewayFtpServer {
38  
39    /**
40     * Take a simple XML file as configuration.
41     *
42     * @param args
43     */
44    public static void main(final String[] args) {
45      if (args.length != 1) {
46        SysErrLogger.FAKE_LOGGER.syserr(
47            "Usage: " + SimpleGatewayFtpServer.class.getName() +
48            " <config-file>");
49        return;
50      }
51      WaarpLoggerFactory.setDefaultFactoryIfNotSame(
52          new WaarpSlf4JLoggerFactory(null));
53      /*
54       * Internal Logger
55       */
56      final WaarpLogger logger =
57          WaarpLoggerFactory.getLogger(SimpleGatewayFtpServer.class);
58      final String config = args[0];
59      final FileBasedConfiguration configuration =
60          new FileBasedConfiguration(SimpleGatewayFtpServer.class,
61                                     SimpleBusinessHandler.class,
62                                     FileSystemBasedDataBusinessHandler.class,
63                                     new FilesystemBasedFileParameterImpl());
64      if (!configuration.setConfigurationFromXml(config)) {
65        SysErrLogger.FAKE_LOGGER.syserr("Bad configuration");
66        return;
67      }
68      // Start server.
69      try {
70        configuration.serverStartup();
71      } catch (final FtpNoConnectionException e) {
72        logger.error("FTP not started", e);
73      }
74      logger.info("FTP started");
75    }
76  
77  }