public boolean start() { try { prepareCache(); ServerSocket serverSocket = null; int port = configuration.getCommandPort(); // Trying to find a port available while (serverSocket == null) { try { serverSocket = new ServerSocket(port); LOG.info("FTPServer started on port '" + port + "'"); } catch (BindException e) { LOG.warn( "Cannot launch the FTPServer on '" + (port++) + "', we try the next port number"); } } dataChannelManager = new FtpDataChannelManagerImpl(configuration); acceptThread = new FtpAcceptThread(this, serverSocket); acceptThread.start(); return true; } catch (Exception exc) { LOG.info("Unhandled exception. " + exc.getMessage(), exc); } return false; }
protected void prepareCache() { String cacheFolderName = configuration.getCacheFolderName(); File cacheFolder = new File(cacheFolderName); if (!PrivilegedFileHelper.exists(cacheFolder)) { LOG.info("Cache folder not exist. Try to create it..."); PrivilegedFileHelper.mkdirs(cacheFolder); } String[] cacheFiles = PrivilegedFileHelper.list(cacheFolder); if (cacheFiles == null) { LOG.info("No cache file in cache folder!"); return; } for (String cacheFile : cacheFiles) { if (cacheFile.endsWith(FtpConst.FTP_CACHEFILEEXTENTION)) { File file = new File(cacheFolderName + "/" + cacheFile); PrivilegedFileHelper.delete(file); } } }