Back from lunch and lets see... nice, it works fine ;)

The source code was verry helpfull, thank you Niklas, Fancis ;)

The "List auths = new ArrayList();" was verry confusing, becaus you can't
find anywhere in the documentation exact specifications "WHAT" exactly a
Authoritys is. Or on the other hand
actually I do my best to understand how the project works and how the
realtionships between the classes are ;)
I am a quite young JAVA-Developer and its a new expirience for me, using
*.jar files and projects from other developers.

However... actually I have create a user "admin" with WritePermission(); he
can downloads files but can not uploads files or creates directorys. So my
next question is: how can I manage a users permissions? I just found
WritePermission();

Here is the actual source (Verry quick & dirty):

package de.gudberg.finetunes.contenthub;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.ftplet.Authentication;
import org.apache.ftpserver.ftplet.AuthenticationFailedException;
import org.apache.ftpserver.ftplet.Authority;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.User;
import org.apache.ftpserver.ftplet.UserManager;
import org.apache.ftpserver.listener.Listener;
import org.apache.ftpserver.listener.ListenerFactory;
import org.apache.ftpserver.ssl.SslConfigurationFactory;
import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
import org.apache.ftpserver.usermanager.SaltedPasswordEncryptor;
import org.apache.ftpserver.usermanager.impl.BaseUser;
import org.apache.ftpserver.usermanager.impl.WritePermission;


public class FtpProxy { 
        
        public static void main(String[] args) throws FtpException {

                FtpServerFactory serverFactory = new FtpServerFactory();
 
                ListenerFactory factory = new ListenerFactory();
                 
                // set the port of the listener
                factory.setPort(2048);

                // replace the default listener
                serverFactory.addListener("default", factory.createListener());
                
                //Create User
 PropertiesUserManagerFactory userManagerFactory = new
PropertiesUserManagerFactory();
 userManagerFactory.setFile(new
File("/home/aleks/server-files/myusers.properties"));
 userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor());
 UserManager um = userManagerFactory.createUserManager();
 
 BaseUser user = new BaseUser();
 user.setName("admin");
 user.setPassword("admin");
 user.setHomeDirectory("/home/aleks/admin");
 user.setEnabled(true);

 // Create Authorities
 List auths = new ArrayList(); // this here was verry confusing ;)
 
 // write permission
 Authority auth = new WritePermission(); 
 auths.add(auth);
 
 um.save(user);
 
 user.setAuthorities(auths);

 serverFactory.setUserManager(um);
 
                // start the server
                FtpServer server = serverFactory.createServer();
                

                
                boolean error = true;

                //anchor, server is running until the user insert "shutdown" 
                try{
                        server.start();
                        System.out.println("FTP-Proxy wurde erfolgreich 
gestartet!");
                        System.out.println("");
                        BufferedReader in = new BufferedReader(new 
InputStreamReader(System.in));
                        boolean shutdown = false;
                        while (!shutdown){
                                System.out.print("FTP-Proxy läuft, \"shutdown\" 
eingeben um Proxy
herunterzufahren!:");
                                String command = in.readLine();
                                if(command.equals("shutdown")){
                                        System.out.println("FTP-Proxy wird 
heruntergefahren!");
                                        server.stop();
                                        shutdown = true;
                                }
                        }
                }catch (Exception e){
                        System.out.println(e);
                        error = false;
                }
                if (!error)
                        System.out.println("FTP-Proxy konnte nicht gestartet 
werden!");
                else
                        System.out.println("FTP-Proxy beendet!!!");
                
        }

}

 
----------------original message-----------------
From: "Niklas Gustavsson" [email protected]
To: [email protected]
Date: Fri, 6 Mar 2009 13:00:17 +0100
-------------------------------------------------
 
 
> On Fri, Mar 6, 2009 at 12:03 PM, Aleksandar Jovanovic
> [email protected] wrote:
>> I just fly over the source, but it's quite that what I am looking for.
>> The server should run as a part of a bigger application, first of all it
is
>> important to be able to connect and upload a file.
> 
> Of course, you might want to integrate with the over all user
> management in your application, via a custom UserManager.
> 
> /niklas
> 
> 


Reply via email to