this is what we use in out rests
public class SimpleFtpServer {
private static final Logger logger =
Logger.getLogger(SimpleFtpServer.class);
public static final String DEFAULT_PATH = "src/test/resources/repo";
public static final int DEFAULT_PORT = 10021;
public static final String DEFAULT_USER = "test";
public static final String DEFAULT_PASSWORD = "test";
public static final String DEFAULT_URL =
"ftp://"+DEFAULT_USER+":"+DEFAULT_PASSWORD+"@localhost:"+DEFAULT_PORT;
private FtpServer server;
/**
* @param args
*/
public static void main(String[] args) {
try {
new SimpleFtpServer().start();
} catch (Exception e) {
e.printStackTrace();
}
}
public void start() throws FtpException{
this.start(DEFAULT_PATH, DEFAULT_PORT);
}
public void start(final String path, final int port) throws
FtpException {
ListenerFactory factory = new ListenerFactory();
factory.setPort(port);
PropertiesUserManagerFactory userManagerFactory = new
PropertiesUserManagerFactory();
userManagerFactory.setPasswordEncryptor(new
SaltedPasswordEncryptor());
userManagerFactory.setAdminName(DEFAULT_USER);
UserManager um = userManagerFactory.createUserManager();
BaseUser user = new BaseUser();
user.setName(DEFAULT_USER);
user.setPassword(DEFAULT_PASSWORD);
user.setHomeDirectory(path);
List<Authority> auths = new ArrayList<Authority>();
Authority auth = new WritePermission();
auths.add(auth);
user.setAuthorities(auths);
um.save(user);
FtpServerFactory serverFactory = new FtpServerFactory();
// replace the default listener
serverFactory.addListener("default", factory.createListener());
// serverFactory.getFtplets().put("SfvCheckFtpLet", new
// SfvCheckFtpLet());
serverFactory.setUserManager(um);
server = serverFactory.createServer();
// add shutdown hook if possible
addShutdownHook(server);
// start the server
server.start();
logger.info("Serving folder: " + new
File(path).getAbsolutePath());
logger.info("Try connecting to ftp://test:t...@localhost:" +
port);
}
public void stop() {
server.stop();
}
private static void addShutdownHook(final FtpServer server) {
// create shutdown hook
Runnable shutdownHook = new Runnable() {
public void run() {
System.out.println("Stopping server...");
server.stop();
}
};
// add shutdown hook
Runtime runtime = Runtime.getRuntime();
runtime.addShutdownHook(new Thread(shutdownHook));
}
}
On Fri, Mar 6, 2009 at 12:03 PM, Aleksandar Jovanovic
<[email protected]> wrote:
> Thank you Niklas,
>
> 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.
>
> For now I am appreciate for your help ;)
>
> greetings,
> Aleks
>
>
>
--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.