org.apache.ftpserver.ftplet.FtpException Java Examples
The following examples show how to use
org.apache.ftpserver.ftplet.FtpException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FtpServerManager.java From db with GNU Affero General Public License v3.0 | 6 votes |
public void setUser(final String datastore, final String password) throws OperationException { removeUser(datastore); //is a no-op if the user is not present BaseUser baseUser = new BaseUser(); baseUser.setAuthorities(defaultAuthorities); baseUser.setName(datastore); baseUser.setPassword(password); baseUser.setHomeDirectory(PathUtil.datastoreFtpFolder(datastore)); try { userManager.save(baseUser); } catch (FtpException e) { e.printStackTrace(); throw new OperationException(ErrorCode.INTERNAL_OPERATION_ERROR, "Error occurred in creating FTP user for datastore: " + datastore); } }
Example #2
Source File: PFtpServer.java From PHONK with GNU General Public License v3.0 | 6 votes |
public void start() { FtpServerFactory serverFactory = new FtpServerFactory(); ListenerFactory factory = new ListenerFactory(); factory.setPort(mPort); // replace the default listener serverFactory.addListener("default", factory.createListener()); serverFactory.setUserManager(um); Map ftpLets = new HashMap<>(); ftpLets.put("ftpLet", new CallbackFTP(mCallback)); serverFactory.setFtplets(ftpLets); // start the server try { server = serverFactory.createServer(); server.start(); MLog.d(TAG, "server started"); } catch (FtpException e) { e.printStackTrace(); MLog.d(TAG, "server not started"); } }
Example #3
Source File: PFtpServer.java From PHONK with GNU General Public License v3.0 | 6 votes |
public void addUser(String name, String pass, String directory, boolean canWrite) { BaseUser user = new BaseUser(); user.setName(name); user.setPassword(pass); //String root = ProjectManager.getInstance().getCurrentProject().getStoragePath() + "/" + directory; user.setHomeDirectory(directory); //check if user can write if (canWrite) { List<Authority> auths = new ArrayList<Authority>(); Authority auth = new WritePermission(); auths.add(auth); user.setAuthorities(auths); } try { um.save(user); } catch (FtpException e) { e.printStackTrace(); } }
Example #4
Source File: DHuSFtpUserManager.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
@Override public String[] getAllUserNames() throws FtpException { DetachedCriteria criteria = DetachedCriteria.forClass ( fr.gael.dhus.database.object.User.class); criteria.add (Restrictions.eq ("deleted", false)); List<fr.gael.dhus.database.object.User> users = userService.getUsers ( criteria, 0, 0); List<String> names = new LinkedList<> (); for (fr.gael.dhus.database.object.User user : users) { names.add (user.getUsername ()); } return names.toArray(new String[names.size()]); }
Example #5
Source File: CamelFtpBaseTest.java From jbpm-work-items with Apache License 2.0 | 6 votes |
public FtpServerBuilder addUser(final String username, final String password, final File home, final boolean write) throws FtpException { UserFactory userFactory = new UserFactory(); userFactory.setHomeDirectory(home.getAbsolutePath()); userFactory.setName(username); userFactory.setPassword(password); if (write) { List<Authority> authorities = new ArrayList<Authority>(); Authority writePermission = new WritePermission(); authorities.add(writePermission); userFactory.setAuthorities(authorities); } User user = userFactory.createUser(); ftpServerFactory.getUserManager().save(user); return this; }
Example #6
Source File: CamelFtpBaseTest.java From jbpm-work-items with Apache License 2.0 | 6 votes |
/** * Start the FTP server, create & clean home directory */ @Before public void initialize() throws FtpException, IOException { File tempDir = new File(System.getProperty("java.io.tmpdir")); ftpRoot = new File(tempDir, "ftp"); if (ftpRoot.exists()) { FileUtils.deleteDirectory(ftpRoot); } boolean created = ftpRoot.mkdir(); if (!created) { throw new IllegalArgumentException("FTP root directory has not been created, " + "check system property java.io.tmpdir"); } String fileName = "test_file_" + CamelFtpTest.class.getName() + "_" + UUID.randomUUID().toString(); File testDir = new File(ftpRoot, "testDirectory"); testFile = new File(testDir, fileName); server = configureFtpServer(new FtpServerBuilder()); server.start(); }
Example #7
Source File: DHuSFtpProductViewByCollection.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
@Override public FtpFile getWorkingDirectory () throws FtpException { if (currentPath.contains (CONTENT_DATE)) { return new FtpContentDateFile (user, workingCol, pathInfo.get (DATE_YEAR), pathInfo.get(DATE_MONTH), pathInfo.get(DATE_DAY)); } if (workingCol == null) { return getHomeDirectory (); } else { return new FtpCollectionFile (user, workingCol); } }
Example #8
Source File: FtpProviderUserDirTestCase.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Gets option file system factory for local FTP server. */ @Override protected FileSystemFactory getFtpFileSystem() throws IOException { // simulate a non-root home directory by copying test directory to it final File testDir = new File(getTestDirectory()); final File rootDir = new File(testDir, "homeDirIsRoot"); final File homesDir = new File(rootDir, "home"); final File initialDir = new File(homesDir, "test"); FileUtils.deleteDirectory(rootDir); // noinspection ResultOfMethodCallIgnored rootDir.mkdir(); FileUtils.copyDirectory(testDir, initialDir, pathname -> !pathname.getPath().contains(rootDir.getName())); return new NativeFileSystemFactory() { @Override public FileSystemView createFileSystemView(final User user) throws FtpException { final FileSystemView fsView = super.createFileSystemView(user); fsView.changeWorkingDirectory("home/test"); return fsView; } }; }
Example #9
Source File: DHuSFtpServerBean.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
@PostConstruct public void start () throws FtpException { if (server == null) server = ftpServer.createFtpServer(port, passivePort, ftps); if (server.isStopped()) { try { server.start(); } catch (Exception e) { LOGGER.error("Cannot start ftp server: " + e.getMessage ()); } } }
Example #10
Source File: OctopusFTPServer.java From bjoern with GNU General Public License v3.0 | 5 votes |
public void start(String octopusHome) { try { startServer(octopusHome); } catch (FtpException e) { logger.debug("Cannot start FTP Server"); } }
Example #11
Source File: StorageUserManager.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
@Override public String[] getAllUserNames() throws FtpException { String[] names = new String[users.size()]; for (int i = 0; i < users.size(); i++) { names[i] = users.get(i).getName(); } return names; }
Example #12
Source File: StorageUserManager.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean isAdmin(String arg) throws FtpException { if (StringUtils.equals("xadmin", arg)) { return true; } else { return false; } }
Example #13
Source File: PFtpServer.java From PHONK with GNU General Public License v3.0 | 5 votes |
@Override public FtpletResult onDisconnect(FtpSession ftpSession) throws FtpException, IOException { if (callback != null) callback.event("Disconnected: " + ftpSession.getUser().getName()); return FtpletResult.DEFAULT; }
Example #14
Source File: StorageUserManager.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
@Override public User getUserByName(String arg) throws FtpException { for (User o : users) { if (StringUtils.equals(o.getName(), arg)) { return o; } } return null; }
Example #15
Source File: FTPServer.java From portable-ftp-server with GNU General Public License v3.0 | 5 votes |
/** * Start. */ public boolean start(){ stop(); ConnectionConfigFactory configFactory = new ConnectionConfigFactory(); configFactory.setAnonymousLoginEnabled(false); configFactory.setMaxAnonymousLogins(0); configFactory.setMaxLoginFailures(5); configFactory.setLoginFailureDelay(30); configFactory.setMaxThreads(10); configFactory.setMaxLogins(10); ListenerFactory factory = new ListenerFactory(); factory.setPort(port); factory.setIdleTimeout(60); FtpServerFactory serverFactory = new FtpServerFactory(); serverFactory.addListener("default", factory.createListener()); serverFactory.setUserManager(userManager); serverFactory.setConnectionConfig(configFactory.createConnectionConfig()); server = serverFactory.createServer(); try{ server.start(); } catch (FtpException ex){ System.err.println(ex.getMessage()); return false; } return true; }
Example #16
Source File: InMemoryUserManagerTest.java From portable-ftp-server with GNU General Public License v3.0 | 5 votes |
/** * Save ignored T est. * * @throws FtpException the ftp exception */ @Test public void saveIgnoredTEst() throws FtpException{ BaseUser user = new BaseUser(); user.setName("admin2"); user.setPassword(USER); user.setEnabled(true); imum.save(user); User u1 = imum.getUserByName("admin2"); assertNotNull(u1); assertEquals(USER,u1.getName()); }
Example #17
Source File: InMemoryUserManagerTest.java From portable-ftp-server with GNU General Public License v3.0 | 5 votes |
/** * Gets the user names test. * * @return the user names test * @throws FtpException the ftp exception */ @Test public void getUserNamesTest() throws FtpException{ // Exists String[] names = imum.getAllUserNames(); assertNotNull(names); assertTrue(names.length == 1); assertEquals(USER,names[0]); }
Example #18
Source File: InMemoryUserManagerTest.java From portable-ftp-server with GNU General Public License v3.0 | 5 votes |
/** * Delete not work test. * * @throws FtpException the ftp exception */ @Test public void deleteNotWorkTest() throws FtpException{ imum.delete(USER); User user = imum.getUserByName(USER); assertNotNull(user); }
Example #19
Source File: InMemoryUserManagerTest.java From portable-ftp-server with GNU General Public License v3.0 | 5 votes |
/** * User is admin test. * * @throws FtpException the ftp exception */ @Test public void userIsAdminTest() throws FtpException{ // User is allways admin assertEquals(USER,imum.getAdminName()); assertTrue(imum.isAdmin(USER)); }
Example #20
Source File: TestSftpServer.java From nomulus with Apache License 2.0 | 5 votes |
@Override public synchronized void start() throws FtpException { try { logger.atInfo().log("Starting server"); server.start(); stopped = false; } catch (IOException e) { throw new FtpException("Couldn't start server", e); } }
Example #21
Source File: SftpServerRule.java From nomulus with Apache License 2.0 | 5 votes |
/** * Starts an SFTP server on a randomly selected port. * * @return the port on which the server is listening */ public int serve(String user, String pass, File home) throws FtpException { checkState(server == null, "You already have an SFTP server!"); int port = NetworkUtils.pickUnusedPort(); server = createSftpServer(user, pass, home, port); return port; }
Example #22
Source File: OctopusFTPServer.java From bjoern with GNU General Public License v3.0 | 5 votes |
private void startServer(String octopusHome) throws FtpException { factory.setPort(FTP_SERVER_PORT); factory.setServerAddress(FTP_SERVER_HOST); configureAnonymousLogin(octopusHome); serverFactory.addListener("default", factory.createListener()); server = serverFactory.createServer(); server.start(); }
Example #23
Source File: OctopusFTPServer.java From bjoern with GNU General Public License v3.0 | 5 votes |
private void configureAnonymousLogin(String octopusHome) throws FtpException { connectionConfigFactory.setAnonymousLoginEnabled(true); serverFactory.setConnectionConfig(connectionConfigFactory.createConnectionConfig()); BaseUser user = configureAnonymousUser(); Path path = Paths.get(octopusHome, "projects"); String homeDirectory = path.toString(); user.setHomeDirectory(homeDirectory); serverFactory.getUserManager().save(user); }
Example #24
Source File: FtpServerManager.java From db with GNU Affero General Public License v3.0 | 5 votes |
public void removeUser(final String datastore) throws OperationException { try{ if(userManager.doesExist(datastore)) { userManager.delete(datastore); } } catch(FtpException e) { e.printStackTrace(); throw new OperationException(ErrorCode.INTERNAL_OPERATION_ERROR, "Error removing FTP user"); } }
Example #25
Source File: FtpProviderTestCase.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Creates and starts an embedded Apache FTP Server (MINA). * * @param rootDirectory the local FTP server rootDirectory * @param fileSystemFactory optional local FTP server FileSystemFactory * @throws FtpException * @throws IOException */ static void setUpClass(final String rootDirectory, final FileSystemFactory fileSystemFactory) throws FtpException, IOException { if (Server != null) { return; } init(); final FtpServerFactory serverFactory = new FtpServerFactory(); final PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory(); final URL userPropsResource = ClassLoader.getSystemClassLoader().getResource(USER_PROPS_RES); Assert.assertNotNull(USER_PROPS_RES, userPropsResource); propertiesUserManagerFactory.setUrl(userPropsResource); final UserManager userManager = propertiesUserManagerFactory.createUserManager(); final BaseUser user = (BaseUser) userManager.getUserByName("test"); // Pickup the home dir value at runtime even though we have it set in the user prop file // The user prop file requires the "homedirectory" to be set user.setHomeDirectory(rootDirectory); userManager.save(user); serverFactory.setUserManager(userManager); if (fileSystemFactory != null) { serverFactory.setFileSystem(fileSystemFactory); } final ListenerFactory factory = new ListenerFactory(); // set the port of the listener factory.setPort(SocketPort); // replace the default listener serverFactory.addListener("default", factory.createListener()); // start the server Server = serverFactory.createServer(); Server.start(); }
Example #26
Source File: GoogleDriveFtpAdapter.java From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 | 5 votes |
void start() { try { cacheUpdater.start(); server.start(); LOG.info("Application started!"); } catch (FtpException e) { throw new RuntimeException(e); } }
Example #27
Source File: DHuSFtpUserManager.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
@Override public User getUserByName(final String name) throws FtpException { if (name == null) return null; fr.gael.dhus.database.object.User u = userService.getUserNoCheck (name); if (u==null) return null; BaseUser user = new BaseUser(); user.setName(u.getUsername()); user.setPassword(u.getPassword()); user.setEnabled( u.isEnabled() && u.isAccountNonExpired() && u.isAccountNonLocked() && u.isCredentialsNonExpired() && !u.isDeleted()); user.setHomeDirectory("/"); List<Authority> authorities = new ArrayList<>(); authorities.add(new WritePermission ()); // No special limit int maxLogin = 0; int maxLoginPerIP = 0; authorities.add(new ConcurrentLoginPermission(maxLogin, maxLoginPerIP)); int uploadRate = 0; int downloadRate = 0; authorities.add(new TransferRatePermission(downloadRate, uploadRate)); user.setAuthorities(authorities); user.setMaxIdleTime(1000); return user; }
Example #28
Source File: AntHarnessTest.java From ExpectIt with Apache License 2.0 | 5 votes |
@BeforeClass public static void startFtpServer() throws FtpException { FtpServerFactory serverFactory = new FtpServerFactory(); BaseUser user = new BaseUser(); user.setName("ftp"); user.setPassword("secret"); serverFactory.getUserManager().save(user); ListenerFactory factory = new ListenerFactory(); factory.setPort(0); Listener listener = factory.createListener(); serverFactory.addListener("default", listener); ftpServer = serverFactory.createServer(); ftpServer.start(); ftpPort = listener.getPort(); }
Example #29
Source File: DHuSFtpProductViewByCollection.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
@Override public FtpFile getFile (String name) throws FtpException { if (name.equals ("./")) { return getWorkingDirectory (); } String identifier = name.substring (0, (name.length () - 4)); Product p = productService.getProductIdentifier (identifier); return new FtpProductFile (user, workingCol, p); }
Example #30
Source File: FtpFileSystemFactory.java From ProjectX with Apache License 2.0 | 5 votes |
@Override public FileSystemView createFileSystemView(User user) throws FtpException { if (!(user instanceof FtpUser)) throw new FtpException("Unsupported user type."); final FileSystemView view = ((FtpUser) user).getFileSystemViewAdapter().createFileSystemView(); if (view == null) throw new FtpException("Cannot create file system view."); return view; }