本文整理匯總了Java中org.apache.ftpserver.FtpServer類的典型用法代碼示例。如果您正苦於以下問題:Java FtpServer類的具體用法?Java FtpServer怎麽用?Java FtpServer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FtpServer類屬於org.apache.ftpserver包,在下文中一共展示了FtpServer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createServer
import org.apache.ftpserver.FtpServer; //導入依賴的package包/類
public static FtpServer createServer(int port, int maxLoginFailures, int loginFailureDelay,
boolean anonymousEnable, String anonymousHomeDirectory,
FTPUser... users) {
final ListenerFactory listener = new ListenerFactory();
listener.setPort(port);
listener.setDataConnectionConfiguration(
new DataConnectionConfigurationFactory().createDataConnectionConfiguration());
ConnectionConfigFactory connection = new ConnectionConfigFactory();
connection.setMaxLoginFailures(maxLoginFailures);
connection.setLoginFailureDelay(loginFailureDelay);
connection.setAnonymousLoginEnabled(anonymousEnable);
final FtpServerFactory server = new FtpServerFactory();
server.setUserManager(new FTPUserManager(anonymousEnable, anonymousHomeDirectory, users));
server.setFileSystem(FTPFileSystemFactory.getInstance());
server.addListener("default", listener.createListener());
server.setConnectionConfig(connection.createConnectionConfig());
return server.createServer();
}
示例2: setUp
import org.apache.ftpserver.FtpServer; //導入依賴的package包/類
/**
* @throws Exception
*
* @see junit.framework.TestCase#setUp()
*/
public void setUp() throws Exception {
System.out.println("------------------------- " + getName() + " -------------------------\n");
// clear old home directory
if (new File(FTP_HOME).exists()) {
assertTrue("failed to clear FTP directory", delete(new File(FTP_HOME)));
}
ApplicationContext context = new ClassPathXmlApplicationContext("xml/spring/datup/local/test/InterfaceContext.xml");
this.ftp = (FtpFactory) context.getBean("ftpFactory");
this.config = (Configuration) context.getBean("datupConfiguration");
this.server = (FtpServer) context.getBean("testFtpServer");
server.start();
config.load().setProperty(Configuration.FTP_USERNAME, USER);
config.load().setProperty(Configuration.FTP_PASSWORD, PASS);
config.load().setProperty(Configuration.FTP_HOSTNAME, HOST);
config.load().setProperty(Configuration.FTP_PORT, PORT);
config.load().setProperty(Configuration.FTP_WORKING_DIRECTORY, "pharmacy");
config.load().setProperty(Configuration.FTP_PENDING_DIRECTORY, "pending");
}
示例3: createServer
import org.apache.ftpserver.FtpServer; //導入依賴的package包/類
private FtpServer createServer() {
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(FTP_PORT);
serverFactory.addListener("default", listenerFactory.createListener());
PropertiesUserManagerFactory managerFactory = new PropertiesUserManagerFactory();
managerFactory.setPasswordEncryptor(new ClearTextPasswordEncryptor());
managerFactory.setFile(new File("src/test/resources/users.properties"));
UserManager createUserManager = managerFactory.createUserManager();
serverFactory.setUserManager(createUserManager);
NativeFileSystemFactory fileSystemFactory = new NativeFileSystemFactory();
fileSystemFactory.setCreateHome(true);
serverFactory.setFileSystem(fileSystemFactory);
return serverFactory.createServer();
}
示例4: 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);
}
}
示例5: doPost
import org.apache.ftpserver.FtpServer; //導入依賴的package包/類
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
FtpServer server = (FtpServer) getServletContext().getAttribute(FtpServerListener.FTPSERVER_CONTEXT_NAME);
if(req.getParameter("stop") != null) {
server.stop();
} else if(req.getParameter("resume") != null) {
server.resume();
} else if(req.getParameter("suspend") != null) {
server.suspend();
}
resp.sendRedirect("/");
}
示例6: 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);
}
}
示例7: 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();
}
}
示例8: createServer
import org.apache.ftpserver.FtpServer; //導入依賴的package包/類
protected FtpServer createServer(String config) {
String completeConfig = "<server id=\"server\" xmlns=\"http://mina.apache.org/ftpserver/spring/v1\" "
+ "xmlns:beans=\"http://www.springframework.org/schema/beans\" "
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ "xsi:schemaLocation=\" "
+ "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd "
+ "http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd "
+ "\">"
+ config
+ "</server>";
XmlBeanFactory factory = new XmlBeanFactory(
new ByteArrayResource(completeConfig.getBytes()));
return (FtpServer) factory.getBean("server");
}
示例9: 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);
}
示例10: 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();
}
}
示例11: 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);
}
}
示例12: ftpServer
import org.apache.ftpserver.FtpServer; //導入依賴的package包/類
@Bean
FtpServer ftpServer(UserManager userManager, Listener nioListener, FileSystemFactory fileSystemFactory) throws FtpException {
FtpServerFactory ftpServerFactory = new FtpServerFactory();
ftpServerFactory.setListeners(Collections.singletonMap("default", nioListener));
ftpServerFactory.setFileSystem(fileSystemFactory);
ftpServerFactory.setUserManager(userManager);
return ftpServerFactory.createServer();
}
示例13: testInitBySpring
import org.apache.ftpserver.FtpServer; //導入依賴的package包/類
/**
* Test method for {@link ch.sdi.core.impl.ftp.FtpExecutor#executeUpload(java.io.InputStream, java.lang.String)}.
*/
@Test
public void testInitBySpring() throws Throwable
{
myLog.debug( "Testing self-initialize by Spring context" );
String targetDir = myTargetDirLocal;
cleanTargetDir( targetDir );
Map<String, InputStream> filesToUpload = createFileUploadMap( targetDir );
TestUtils.addToEnvironment( myEnv, SdiMainProperties.KEY_FTP_CMD_LINE,
"-A localhost" );
registerFtpUser( "anonymous",
System.getProperty( "user.name" ) + "@" + InetAddress.getLocalHost().getHostName() );
FtpServer server = startFtpServer();
try
{
// omit call to init in order to auto initialize by spring context
myClassUnderTest.connectAndLogin();
myClassUnderTest.uploadFiles( filesToUpload );
myClassUnderTest.logoutAndDisconnect();
assertFilesUploaded( createFileUploadMap( targetDir ) );
}
finally
{
if ( server != null )
{
myLog.debug( "stopping the embedded FTP server" );
server.stop();
} // if myServer != null
}
}
示例14: testUploadAnonymous
import org.apache.ftpserver.FtpServer; //導入依賴的package包/類
/**
* Test method for {@link ch.sdi.core.impl.ftp.FtpExecutor#executeUpload(java.io.InputStream, java.lang.String)}.
*/
@Test
public void testUploadAnonymous() throws Throwable
{
myLog.debug( "Testing Anonymous login" );
String targetDir = myTargetDirLocal;
cleanTargetDir( targetDir );
Map<String, InputStream> filesToUpload = createFileUploadMap( targetDir );
List<String> args = new ArrayList<String>();
args.add( "-bla" ); // invalid option should be ignored
args.add( "-A" ); // anonymous
args.add( "localhost" );
registerFtpUser( "anonymous",
System.getProperty( "user.name" ) + "@" + InetAddress.getLocalHost().getHostName() );
FtpServer server = startFtpServer();
try
{
myClassUnderTest.init( args.toArray( new String[args.size()] ) );
myClassUnderTest.connectAndLogin();
myClassUnderTest.uploadFiles( filesToUpload );
myClassUnderTest.logoutAndDisconnect();
assertFilesUploaded( createFileUploadMap( targetDir ) );
}
finally
{
if ( server != null )
{
myLog.debug( "stopping the embedded FTP server" );
server.stop();
} // if myServer != null
}
}
示例15: testUploadLogin
import org.apache.ftpserver.FtpServer; //導入依賴的package包/類
/**
* Test method for {@link ch.sdi.core.impl.ftp.FtpExecutor#executeUpload(java.io.InputStream, java.lang.String)}.
*/
@Test
public void testUploadLogin() throws Throwable
{
myLog.debug( "Testing normal login" );
String targetDir = myTargetDirLocal;
cleanTargetDir( targetDir );
Map<String, InputStream> filesToUpload = createFileUploadMap( targetDir );
List<String> args = new ArrayList<String>();
args.add( "localhost" );
args.add( "heri" ); // user
args.add( "heri" ); // pw
registerFtpUser( "heri", "heri" );
FtpServer server = startFtpServer();
try
{
myClassUnderTest.init( args.toArray( new String[args.size()] ) );
myClassUnderTest.connectAndLogin();
myClassUnderTest.uploadFiles( filesToUpload );
myClassUnderTest.logoutAndDisconnect();
assertFilesUploaded( createFileUploadMap( targetDir ) );
}
finally
{
if ( server != null )
{
myLog.debug( "stopping the embedded FTP server" );
server.stop();
} // if myServer != null
}
}