本文整理匯總了Java中org.apache.ftpserver.FtpServer.start方法的典型用法代碼示例。如果您正苦於以下問題:Java FtpServer.start方法的具體用法?Java FtpServer.start怎麽用?Java FtpServer.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.ftpserver.FtpServer
的用法示例。
在下文中一共展示了FtpServer.start方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startFtpServer
import org.apache.ftpserver.FtpServer; //導入方法依賴的package包/類
public static FtpServer startFtpServer(String homePath, int port, String user, String pass) {
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(port);
serverFactory.addListener("default", listenerFactory.createListener());
serverFactory.setUserManager(new FtpUserManager(homePath, user, pass));
FtpServer ftpServer = serverFactory.createServer();
try {
ftpServer.start();
return ftpServer;
} catch (FtpException e) {
throw new RuntimeException(e);
}
}
示例2: contextInitialized
import org.apache.ftpserver.FtpServer; //導入方法依賴的package包/類
public void contextInitialized(ServletContextEvent sce) {
System.out.println("Starting FtpServer");
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
FtpServer server = (FtpServer) ctx.getBean("myServer");
sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server);
try {
server.start();
System.out.println("FtpServer started");
} catch (Exception e) {
throw new RuntimeException("Failed to start FtpServer", e);
}
}
示例3: main
import org.apache.ftpserver.FtpServer; //導入方法依賴的package包/類
/**
* This method is the FtpServer starting point when running by using the
* command line mode.
*
* @param args
* The first element of this array must specify the kind of
* configuration to be used to start the server.
*/
public static void main(String args[]) {
CommandLine cli = new CommandLine();
try {
// get configuration
FtpServer server = cli.getConfiguration(args);
if (server == null) {
return;
}
// start the server
server.start();
System.out.println("FtpServer started");
// add shutdown hook if possible
cli.addShutdownHook(server);
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例4: startServer
import org.apache.ftpserver.FtpServer; //導入方法依賴的package包/類
/**
* Start the FTP server.
*/
public void startServer() {
//Set the user factory
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
String filename = mContext.getExternalCacheDir().getAbsolutePath() + "/users.properties";
File files = new File(filename);
userManagerFactory.setFile(files);
//Set the server factory
FtpServerFactory serverFactory = new FtpServerFactory();
serverFactory.setUserManager(userManagerFactory.createUserManager());
//Set the port number
ListenerFactory factory = new ListenerFactory();
factory.setPort(PORT_NUMBER);
try {
serverFactory.addListener("default", factory.createListener());
FtpServer server = serverFactory.createServer();
mFtpServer = server;
//Start the server
server.start();
} catch (FtpException e) {
e.printStackTrace();
}
Log.d(TAG, "onCreate: FTP server started. IP address: " + getLocalIpAddress() + " and Port:" + PORT_NUMBER);
}
示例5: Config2
import org.apache.ftpserver.FtpServer; //導入方法依賴的package包/類
void Config2() {
// Now, let's make it possible for a client to use FTPS (FTP over SSL) for the default listener.
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory factory = new ListenerFactory();
// set the port of the listener
factory.setPort(2221);
// define SSL configuration
SslConfigurationFactory ssl = new SslConfigurationFactory();
ssl.setKeystoreFile(new File(ftpConfigDir + "ftpserver.jks"));
ssl.setKeystorePassword("password");
// set the SSL configuration for the listener
factory.setSslConfiguration(ssl.createSslConfiguration());
factory.setImplicitSsl(true);
// replace the default listener
serverFactory.addListener("default", factory.createListener());
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
userManagerFactory.setFile(new File(ftpConfigDir + "users.properties"));
serverFactory.setUserManager(userManagerFactory.createUserManager());
// start the server
FtpServer server = serverFactory.createServer();
this.mFtpServer = server;
try {
server.start();
} catch (FtpException e) {
e.printStackTrace();
}
}
示例6: startServer
import org.apache.ftpserver.FtpServer; //導入方法依賴的package包/類
private void startServer() {
try {
DefaultFtpServerContext context = new DefaultFtpServerContext(false);
MinaListener listener = new MinaListener();
// Set port to 0 for OS to give a free port
listener.setPort(0);
context.setListener("default", listener);
// Create a test user.
UserManager userManager = context.getUserManager();
BaseUser adminUser = new BaseUser();
adminUser.setName("admin");
adminUser.setPassword("admin");
adminUser.setEnabled(true);
adminUser.setAuthorities(new Authority[] { new WritePermission() });
Path adminUserHome = new Path(ftpServerRoot, "user/admin");
adminUser.setHomeDirectory(adminUserHome.toUri().getPath());
adminUser.setMaxIdleTime(0);
userManager.save(adminUser);
// Initialize the server and start.
server = new FtpServer(context);
server.start();
} catch (Exception e) {
throw new RuntimeException("FTP server start-up failed", e);
}
}
示例7: startFtpServer
import org.apache.ftpserver.FtpServer; //導入方法依賴的package包/類
/**
* @return
* @throws FtpException
*/
private FtpServer startFtpServer() throws FtpException
{
FtpServer result;
result = myServerFactory.createServer();
myLog.debug( "starting an embedded FTP server" );
result.start();
return result;
}
示例8: main
import org.apache.ftpserver.FtpServer; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory factory = new ListenerFactory();
// set the port of the listener
factory.setPort(2221);
// define SSL configuration
SslConfigurationFactory ssl = new SslConfigurationFactory();
ssl.setKeystoreFile(new File("src/test/resources/ftpserver.jks"));
ssl.setKeystorePassword("password");
// set the SSL configuration for the listener
factory.setSslConfiguration(ssl.createSslConfiguration());
factory.setImplicitSsl(true);
// replace the default listener
serverFactory.addListener("default", factory.createListener());
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
userManagerFactory.setFile(new File("myusers.properties"));
serverFactory.setUserManager(userManagerFactory.createUserManager());
// start the server
FtpServer server = serverFactory.createServer();
server.start();
}
示例9: testFailStartingSecondListener
import org.apache.ftpserver.FtpServer; //導入方法依賴的package包/類
public void testFailStartingSecondListener() throws Exception {
// FTPSERVER-197
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(0);
// let's create two listeners on the same port, second should not start
Listener defaultListener = listenerFactory.createListener();
Listener secondListener = listenerFactory.createListener();
serverFactory.addListener("default", defaultListener);
serverFactory.addListener("second", secondListener);
FtpServer server = serverFactory.createServer();
try {
server.start();
// Windows seems to allow for both listeners to bind on the same port...
//fail("Must throw FtpServerConfigurationException");
} catch(FtpServerConfigurationException e) {
if(e.getCause() instanceof BindException) {
// OK!
// we failed to start, make sure things are shut down correctly
assertTrue(defaultListener.isStopped());
assertTrue(secondListener.isStopped());
assertTrue(server.isStopped());
} else {
throw e;
}
}
}
示例10: createSftpServer
import org.apache.ftpserver.FtpServer; //導入方法依賴的package包/類
private static FtpServer createSftpServer(String user, String pass, File home, int port)
throws FtpException {
FtpServer server = TestSftpServer.createSftpServer(user, pass, null, port, home);
server.start();
return server;
}
示例11: ftpServerFactory
import org.apache.ftpserver.FtpServer; //導入方法依賴的package包/類
public static FtpServer ftpServerFactory(String name, HashMap<String, ConfigurationItem> all_instances_confs, HashMap<String, Ftplet> ftplets) throws Exception {
FtpServerFactory server_factory = new FtpServerFactory();
LinkedHashMap<String, Object> log = new LinkedHashMap<String, Object>();
DataConnectionConfigurationFactory dccf = new DataConnectionConfigurationFactory();
dccf.setActiveEnabled(true);
dccf.setActiveIpCheck(true);
log.put("active", dccf.isActiveEnabled());
log.put("active IP check", dccf.isActiveIpCheck());
ConfigurationClusterItem local = Configuration.getClusterConfiguration(all_instances_confs, name, "active", "0.0.0.0", 20).get(0);
dccf.setActiveLocalAddress(local.address);
dccf.setActiveLocalPort(local.port);
log.put("active local", dccf.getActiveLocalAddress() + ":" + dccf.getActiveLocalPort());
int idle = Configuration.getValue(all_instances_confs, name, "idle", 300);
dccf.setIdleTime(idle);
log.put("Idle time", dccf.getIdleTime());
dccf.setImplicitSsl(false);
dccf.setPassiveAddress(Configuration.getValue(all_instances_confs, name, "passive-internal", "0.0.0.0"));
dccf.setPassiveExternalAddress(Configuration.getValue(all_instances_confs, name, "passive-external", "0.0.0.0"));
dccf.setPassivePorts(Configuration.getValue(all_instances_confs, name, "passive-ports", "30000-40000"));
log.put("passive", dccf.getPassiveAddress() + ">" + dccf.getPassiveExternalAddress());
log.put("passive ports", dccf.getPassivePorts());
ListenerFactory factory = new ListenerFactory();
factory.setPort(Configuration.getValue(all_instances_confs, name, "listen", 21));
factory.setIpFilter(FTPIpFilter.getFilter());
factory.setIdleTimeout(idle);
log.put("port", factory.getPort());
factory.setDataConnectionConfiguration(dccf.createDataConnectionConfiguration());
server_factory.addListener("default", factory.createListener());
FTPUserManager ftpum;
if (name == "default") {
ftpum = new FTPUserManager("");
} else {
ftpum = new FTPUserManager(name);
server_factory.setUserManager(ftpum);
}
server_factory.setUserManager(ftpum);
log.put("User Manager", ftpum);
server_factory.setFtplets(ftplets);
Loggers.FTPserver.info("Start FTP Server: " + log);
FtpServer server = server_factory.createServer();
server.start();
return server;
}