當前位置: 首頁>>代碼示例>>Java>>正文


Java FtpServer類代碼示例

本文整理匯總了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();
}
 
開發者ID:AlexMofer,項目名稱:ProjectX,代碼行數:22,代碼來源:FTPHelper.java

示例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");
}
 
開發者ID:OSEHRA-Sandbox,項目名稱:MOCHA,代碼行數:28,代碼來源:FtpTest.java

示例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();
}
 
開發者ID:tadayosi,項目名稱:samples-switchyard,代碼行數:18,代碼來源:FTPServer.java

示例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);
    }
}
 
開發者ID:bingoohuang,項目名稱:aoc,代碼行數:17,代碼來源:TestUtils.java

示例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("/");
}
 
開發者ID:saaconsltd,項目名稱:mina-ftpserver,代碼行數:17,代碼來源:FtpServerServlet.java

示例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);
    }
}
 
開發者ID:saaconsltd,項目名稱:mina-ftpserver,代碼行數:17,代碼來源:FtpServerListener.java

示例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();
    }
}
 
開發者ID:saaconsltd,項目名稱:mina-ftpserver,代碼行數:30,代碼來源:CommandLine.java

示例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");

}
 
開發者ID:saaconsltd,項目名稱:mina-ftpserver,代碼行數:18,代碼來源:SpringConfigTestTemplate.java

示例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);
}
 
開發者ID:kevalpatel2106,項目名稱:remote-storage-android-things,代碼行數:31,代碼來源:FTPManager.java

示例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();
        }
    }
 
開發者ID:lucky-code,項目名稱:Practice,代碼行數:38,代碼來源:FtpActivity.java

示例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);
  }
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:30,代碼來源:TestFTPFileSystem.java

示例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();
}
 
開發者ID:joshlong,項目名稱:cloudfoundry-ftp-service-broker,代碼行數:9,代碼來源:FtpServerConfiguration.java

示例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
    }
}
 
開發者ID:heribender,項目名稱:SocialDataImporter,代碼行數:37,代碼來源:FtpExecutorTest.java

示例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
    }
}
 
開發者ID:heribender,項目名稱:SocialDataImporter,代碼行數:39,代碼來源:FtpExecutorTest.java

示例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
    }
}
 
開發者ID:heribender,項目名稱:SocialDataImporter,代碼行數:38,代碼來源:FtpExecutorTest.java


注:本文中的org.apache.ftpserver.FtpServer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。