Changeset 717


Ignore:
Timestamp:
Jun 3, 2008, 9:19:40 AM (15 years ago)
Author:
Nicklas Nordborg
Message:

References #114: Implement FTP Server

Stopping and starting now re-reads the configuration settings. Updated installation, configuration and release documentation.

Location:
extensions/net.sf.basedb.ftp/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.ftp/trunk/README

    r715 r717  
    2323 2. Unpack the downloaded file to a directory of your choice.
    2424 3. Copy the `ftp.config` file to `WEB-INF/classes` directory.
    25  4. The default `ftp.config` file creates a regular FTP service on port 2121.
    26     If you want to use a different port, and/or change other settings edit
    27     the `ftp.config` file. For more information about configuration options see:
     25 4. The default `ftp.config` file creates a regular FTP service with the
     26    control connection on port 2121 accepting connections from the local
     27    host only. To allow extenal connections the three settings listed
     28    below needs to be changed. It should work to change the 127.0.0.1 value
     29    to the ip number (using names doesn't seem to work) of your BASE server.
     30    For more information about configuration options see:
    2831    http://mina.apache.org/ftpserver-documentation.html
     32   
     33    * config.listeners.default.address
     34    * config.listeners.default.data-connection.passive.address
     35    * config.listeners.default.data-connection.passive.external-address
     36   
    2937 5. Copy the `base-ftpserver.jar` file and the `lib` directory, including sub-
    3038    directories and files, to your BASE extensions directory, `WEB-INF/extensions`.
    31  6. Run the 'Extensions -> Manual scan' command to install the extension. If you
     39 6. Run the `Extensions -> Manual scan` command to install the extension. If you
    3240    have enabled automatic installation, just sit back and wait for it to find
    3341    the FTP server extension.
     
    4553   in the `ftp.config` file. Those settings will be replaced by BASE-specific
    4654   options.
     55   
     56 * BASE allows that a directory has the same name as a file. This may confuse
     57   FTP clients since that is normally not allowed. The result for certain
     58   operations is undefined for files and directories that has the same name.
    4759
    4860== Compiling ==
  • extensions/net.sf.basedb.ftp/trunk/RELEASE

    r714 r717  
    33===================================================
    44
    5 TODO
     5Follow these instructions to release version A.B of
     6this package. Please update the instructions if you
     7find anything that is not correct or missing.
     8
     9 1. Make sure that all changes have been committed to
     10    the trunk. Check with other developers if not
     11    sure.
     12
     13 2. Update the version number.
     14   
     15    * In build.xml: <property name="version" value="A.B" />
     16    * In META-INF/extensions.xml: <version>A.B</version>
     17
     18 3. Make sure that the code compiles and can be packaged.
     19 
     20    ant package
     21   
     22    will create the file 'base-ftpserver-A.B.tar.gz' in
     23    the project directory.
     24 
     25 4. Make sure that the installation of the FTP Server works
     26    and that the installation instructions are up to date.
     27   
     28 5. When everything is OK, commit any changes to subversion.
     29
     30 6. Create a tag in subversion:
     31
     32    svn copy http://baseplugins.thep.lu.se/svn/extensions/net.sf.basedb.ftp/trunk \
     33        http://baseplugins.thep.lu.se/svn/extensions/net.sf.basedb.ftp/tags/A.B \
     34        -m "Tagging release A.B"
     35
     36 7. Upload the packaged release as an attachment to:
     37    http://baseplugins.thep.lu.se/wiki/net.sf.basedb.ftp
     38
     39 8. Edit the http://baseplugins.thep.lu.se/wiki/net.sf.basedb.examples.ftp
     40    page:
     41   
     42    * Add a new entry to the Download table
     43    * Change the README link to point to the tagged release. Use
     44      the following wiki code:
     45      [source:/extensions/net.sf.basedb.ftp/tags/A.B/README README]
     46
     47 9. Create a new milestone: 'FTP Server vA.B+1'
     48
     4910. Close the 'FTP Server A.B' milestone. Move
     50    any remaining tickets to the newly create milestone.
     51
     5211. Update the version number in build.xml.
     53
     54    <property name="version" value="A.B+1pre" />
     55   
     56    Commit the change to subversion:
     57   
     58    svn commit -m "Preparing for future release A.B+1"
    659     
  • extensions/net.sf.basedb.ftp/trunk/ftp.config

    r716 r717  
    4545##-----------------------------------------------------------------------------
    4646config.listeners.default.class=org.apache.ftpserver.listener.mina.MinaListener
    47 config.listeners.default.address=localhost
    48 config.listeners.default.port=21210
     47config.listeners.default.address=127.0.0.1
     48config.listeners.default.port=2121
    4949config.listeners.default.implicit-ssl=false
    5050#config.listeners.default.ssl.class=org.apache.ftpserver.ssl.DefaultSsl
     
    6464config.listeners.default.data-connection.idle-time=10
    6565config.listeners.default.data-connection.active.enable=true
    66 config.listeners.default.data-connection.active.local-address=localhost
    67 config.listeners.default.data-connection.active.local-port=20200
     66config.listeners.default.data-connection.active.local-address=
     67config.listeners.default.data-connection.active.local-port=0
    6868config.listeners.default.data-connection.active.ip-check=false
    69 config.listeners.default.data-connection.passive.address=localhost
     69config.listeners.default.data-connection.passive.address=127.0.0.1
    7070config.listeners.default.data-connection.passive.ports=0
    7171config.listeners.default.data-connection.passive.external-address=127.0.0.1
  • extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/BaseFileSystemView.java

    r716 r717  
    176176      log.debug("   user=" + user);
    177177    }
     178    boolean preferDirectory = fileName.endsWith("/");
    178179    if (fileName.startsWith("./"))
    179180    {
     
    195196     
    196197      // Check if the path represents a file
    197       try
    198       {
    199         Path filePath = new Path(fileName, Path.Type.FILE);
    200         File file = File.getByPath(dc, filePath, false);
    201         fo = new BaseFileObject(user, file);
    202       }
    203       catch (Exception ex)
    204       {
    205         if (log.isDebugEnabled())
    206         {
    207           log.debug("Not a file: " + fileName, ex);
    208         }
    209       }
    210 
    211       if (fo == null)
    212       {
    213         // Check if the path represents a directory
    214         try
    215         {
    216           Path dirPath = new Path(fileName, Path.Type.DIRECTORY);
    217           Directory dir = Directory.getByPath(dc, dirPath);
    218           fo = new BaseFileObject(user, dir);
    219         }
    220         catch (Exception ex)
    221         {
    222           if (log.isDebugEnabled())
    223           {
    224             log.debug("Not a directory: " + fileName, ex);
    225           }
    226         }
    227       }
     198      if (preferDirectory) fo = getDirectory(dc, fileName);
     199      if (fo == null) fo = getFile(dc, fileName);
     200      if (fo == null && !preferDirectory) fo = getDirectory(dc, fileName);
    228201    }
    229202    finally
     
    247220  // ----------------------------------------
    248221
     222  /**
     223    Try to load the given path as a BASE File object.
     224  */
     225  private BaseFileObject getFile(DbControl dc, String path)
     226  {
     227    BaseFileObject fo = null;
     228    try
     229    {
     230      Path filePath = new Path(path, Path.Type.FILE);
     231      File file = File.getByPath(dc, filePath, false);
     232      fo = new BaseFileObject(user, file);
     233    }
     234    catch (Exception ex)
     235    {
     236      if (log.isDebugEnabled())
     237      {
     238        log.debug("Not a file: " + path, ex);
     239      }
     240    }
     241    return fo;
     242  }
     243 
     244  /**
     245    Try to load the given path as a BASE Directory object.
     246  */
     247  private BaseFileObject getDirectory(DbControl dc, String path)
     248  {
     249    BaseFileObject fo = null;
     250    try
     251    {
     252      Path dirPath = new Path(path, Path.Type.DIRECTORY);
     253      Directory dir = Directory.getByPath(dc, dirPath);
     254      fo = new BaseFileObject(user, dir);
     255    }
     256    catch (Exception ex)
     257    {
     258      if (log.isDebugEnabled())
     259      {
     260        log.debug("Not a directory: " + path, ex);
     261      }
     262    }
     263    return fo;
     264  }
     265
     266 
    249267  /**
    250268    Concatenate two paths to create a full path. The concatenation makes
  • extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/FtpServiceController.java

    r716 r717  
    2424package net.sf.basedb.clients.ftp;
    2525
     26import java.io.InputStream;
     27import java.net.URL;
     28import java.util.Properties;
     29
     30import org.slf4j.Logger;
     31import org.slf4j.LoggerFactory;
     32
    2633import net.sf.basedb.clients.web.extensions.service.ServiceControllerAction;
     34import net.sf.basedb.core.ConfigurationException;
    2735
    2836/**
     
    3947  implements ServiceControllerAction
    4048{
     49  private static final Logger log = LoggerFactory.getLogger(FtpServiceController.class);
    4150
    42   private final BaseFtpServer server;
     51  private final String config;
     52  private BaseFtpServer server;
    4353 
    4454  /**
     
    4757    @param server The server to control with this action
    4858  */
    49   public FtpServiceController(BaseFtpServer server)
     59  public FtpServiceController(String config)
    5060  {
    51     this.server = server;
     61    this.config = config == null ? "/ftp.config" : config;
    5262  }
    5363 
     
    5969  public boolean isRunning()
    6070  {
    61     return server.isRunning();
     71    return server != null && server.isRunning();
    6272  }
    6373
     
    6575  public void start()
    6676  {
    67     server.start();
     77    getServer().start();
    6878  }
    6979
     
    7181  public void stop()
    7282  {
    73     server.stop();
     83    if (server != null)
     84    {
     85      server.stop();
     86      server = null;
     87    }
    7488  }
    7589  // ----------------------------------------------
     
    7791  /*
    7892    From the Object class
    79     ---------------------
     93    ---------------------------------------------
    8094  */
    8195  @Override
     
    86100  // ----------------------------------------------
    87101 
    88  
     102  /**
     103    Get or create the {@link BaseFtpServer}. A controller can only be associated
     104    with a single ftp server.
     105  */
     106  private BaseFtpServer getServer()
     107  {
     108    if (server == null)
     109    {
     110      log.info("Creating BASE FTP Server");
     111      try
     112      {
     113        log.debug("config=" + config);
     114        URL configUrl = BaseFtpServer.class.getResource(config);
     115        InputStream is = configUrl == null ? null : configUrl.openStream();
     116        if (is == null)
     117        {
     118          throw new ConfigurationException("Can't find the properties file. " +
     119              "Make sure '" + config + "' is in the CLASSPATH.");
     120        }
     121        Properties config = new Properties();
     122        config.load(is);
     123        is.close();
     124        server = new BaseFtpServer(config);
     125        log.info("BASE FTP Server created successfully");
     126      }
     127      catch (RuntimeException ex)
     128      {
     129        log.error("Could not create BASE FTP Server", ex);
     130        throw ex;
     131      }
     132      catch (Exception ex)
     133      {
     134        log.error("Could not create BASE FTP Server", ex);
     135        throw new RuntimeException(ex);
     136      }
     137    }
     138    return server;
     139  }
    89140
    90141}
  • extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/FtpServiceControllerFactory.java

    r716 r717  
    2424package net.sf.basedb.clients.ftp;
    2525
    26 import java.io.InputStream;
    27 import java.net.URL;
    28 import java.util.Properties;
    29 
    3026import org.slf4j.Logger;
    3127import org.slf4j.LoggerFactory;
    3228
    3329import net.sf.basedb.clients.web.extensions.service.ServiceControllerAction;
    34 import net.sf.basedb.core.ConfigurationException;
    3530import net.sf.basedb.util.extensions.ActionFactory;
    3631import net.sf.basedb.util.extensions.InvokationContext;
     
    5752
    5853  private FtpServiceController[] controller;
    59   private BaseFtpServer server;
    6054  private String config;
    6155 
     
    10195    {
    10296      controller = new FtpServiceController[1];
    103       controller[0] = new FtpServiceController(getServer());
     97      controller[0] = new FtpServiceController(config);
    10498    }
    10599    return controller;
    106100  }
    107101 
    108   /**
    109     Get or create the {@link BaseFtpServer}. A factory can only be associated
    110     with a single ftp server.
    111   */
    112   private BaseFtpServer getServer()
    113   {
    114     if (server == null)
    115     {
    116       log.info("Creating BASE FTP Server");
    117       try
    118       {
    119         if (config == null) config = "/ftp.config";
    120         log.debug("config=" + config);
    121         URL configUrl = BaseFtpServer.class.getResource(config);
    122         InputStream is = configUrl == null ? null : configUrl.openStream();
    123         if (is == null)
    124         {
    125           throw new ConfigurationException("Can't find the properties file. " +
    126               "Make sure '" + config + "' is in the CLASSPATH.");
    127         }
    128         Properties config = new Properties();
    129         config.load(is);
    130         is.close();
    131         server = new BaseFtpServer(config);
    132         log.info("BASE FTP Server created successfully");
    133       }
    134       catch (RuntimeException ex)
    135       {
    136         log.error("Could not create BASE FTP Server", ex);
    137         throw ex;
    138       }
    139       catch (Exception ex)
    140       {
    141         log.error("Could not create BASE FTP Server", ex);
    142         throw new RuntimeException(ex);
    143       }
    144     }
    145     return server;
    146   }
    147  
    148 
    149102}
Note: See TracChangeset for help on using the changeset viewer.