Examples of FTPClient


Examples of org.apache.commons.net.ftp.FTPClient

        // reboot server to clear stats
        server.stop();
        initServer();
       
        // let's generate some stats
        FTPClient client1 = new FTPClient();
        client1.connect("localhost", getListenerPort());
       
        assertTrue(client1.login(ADMIN_USERNAME, ADMIN_PASSWORD));
        assertTrue(client1.makeDirectory("foo"));
        assertTrue(client1.makeDirectory("foo2"));
        assertTrue(client1.removeDirectory("foo2"));
        assertTrue(client1.storeFile(TEST_FILENAME, new ByteArrayInputStream(TESTDATA)));
        assertTrue(client1.storeFile(TEST_FILENAME, new ByteArrayInputStream(TESTDATA)));
        assertTrue(client1.retrieveFile(TEST_FILENAME, new ByteArrayOutputStream()));
        assertTrue(client1.deleteFile(TEST_FILENAME));
       
        assertTrue(client1.logout());
        client1.disconnect();

        FTPClient client2 = new FTPClient();
        client2.connect("localhost", getListenerPort());

        assertTrue(client2.login(ANONYMOUS_USERNAME, ANONYMOUS_PASSWORD));
        // done setting up stats
       
        // send a command to verify that we are correctly logged in
        assertTrue(FTPReply.isPositiveCompletion(client2.noop()));
       
        client.connect("localhost", getListenerPort());
        assertTrue(client.login(ADMIN_USERNAME, ADMIN_PASSWORD));

        if(server.getServerContext().getFtpStatistics().getCurrentLoginNumber() != 2) {
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPClient

    protected boolean isStartServer() {
        return true;
    }

    protected FTPClient createFTPClient() throws Exception {
        FTPClient client = new FTPClient();
        client.setDefaultTimeout(10000);
        return client;
    }
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPClient

        client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
    }

    @Override
    protected FTPClient createFTPClient() throws Exception {
        FTPClient client = new FTPClient();
        client.setControlEncoding("UTF-8");
        return client;
    }
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPClient

     * public void testLoginWithMaxConnectionsMulti() throws Exception { for(int
     * i = 0; i<50; i++) { testLoginWithMaxConnections(); } }
     */

    public void testLoginWithMaxConnections() throws Exception {
        FTPClient client1 = new FTPClient();
        FTPClient client2 = new FTPClient();
        FTPClient client3 = new FTPClient();
        FTPClient client4 = new FTPClient();

        try {
            client1.connect("localhost", getListenerPort());
            client2.connect("localhost", getListenerPort());
            client3.connect("localhost", getListenerPort());
            client4.connect("localhost", getListenerPort());

            assertTrue(client1.login(TESTUSER1_USERNAME, TESTUSER_PASSWORD));
            assertTrue(client2.login(TESTUSER1_USERNAME, TESTUSER_PASSWORD));
            assertTrue(client3.login(TESTUSER1_USERNAME, TESTUSER_PASSWORD));

            try {
                assertTrue(client4.login(TESTUSER1_USERNAME, TESTUSER_PASSWORD));
                assertEquals(421, client.getReplyCode());
                fail("Must throw FTPConnectionClosedException");
            } catch (FTPConnectionClosedException e) {
                // expected
            }
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPClient

*
*/
public class BindExceptionSerialTest extends ClientTestTemplate {
    @Override
    protected FTPClient createFTPClient() throws Exception {
        FTPClient c = super.createFTPClient();
        c.setDataTimeout(1000);
        return c;
    }
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPClient

            password = "anonymous";
        }

        try
        {
            final FTPClient client = new FTPClient();

            FTPFileEntryParserFactory myFactory = FtpFileSystemConfigBuilder.getInstance().getEntryParserFactory(fileSystemOptions);
            if (myFactory != null)
            {
                client.setParserFactory(myFactory);
            }

            try
            {
              if(System.getProperty("org.apache.commons.net.socketFactory", null)!=null) {
                               
                try {
                SocketFactory socketFactory = (SocketFactory) Class.forName(System.getProperty("org.apache.commons.net.socketFactory")).newInstance();
                client.setSocketFactory(socketFactory);
                } catch(Throwable t) {
                  throw new FileSystemException(t);
                }
              }
                client.connect(hostname, port);

                int reply = client.getReplyCode();
                if (!FTPReply.isPositiveCompletion(reply))
                {
                    throw new FileSystemException("vfs.provider.ftp/connect-rejected.error", hostname);
                }

                // Login
                if (!client.login(username, password))
                {
                    throw new FileSystemException("vfs.provider.ftp/login.error", new Object[]{hostname, username}, null);
                }

                // Set binary mode
                if (!client.setFileType(FTP.BINARY_FILE_TYPE))
                {
                    throw new FileSystemException("vfs.provider.ftp/set-binary.error", hostname);
                }

                // Set dataTimeout value
                Integer dataTimeout = FtpFileSystemConfigBuilder.getInstance().getDataTimeout(fileSystemOptions);
                if (dataTimeout != null)
                {
                    client.setDataTimeout(dataTimeout.intValue());
                }

                // Change to root by default
                // All file operations a relative to the filesystem-root
                // String root = getRoot().getName().getPath();

                Boolean userDirIsRoot = FtpFileSystemConfigBuilder.getInstance().getUserDirIsRoot(fileSystemOptions);
                if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue()))
                {
                    if (!client.changeWorkingDirectory(workingDirectory))
                    {
                        throw new FileSystemException("vfs.provider.ftp/change-work-directory.error", workingDirectory);
                    }
                }

                Boolean passiveMode = FtpFileSystemConfigBuilder.getInstance().getPassiveMode(fileSystemOptions);
                if (passiveMode != null && passiveMode.booleanValue())
                {
                    client.enterLocalPassiveMode();
                }
            }
            catch (final IOException e)
            {
                if (client.isConnected())
                {
                    client.disconnect();
                }
                throw e;
            }

            return client;
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPClient

        if (args.length == 4)
        {
            dir = args[3];
        }

        FTPClient client = new FTPClient();
        client.connect(host);
        int reply = client.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply))
        {
            throw new IllegalArgumentException("cant connect: " + reply);
        }
        if (!client.login(user, pass))
        {
            throw new IllegalArgumentException("login failed");
        }
        client.enterLocalPassiveMode();

        OutputStream os = client.storeFileStream(dir + "/test.txt");
        if (os == null)
        {
            throw new IllegalStateException(client.getReplyString());
        }
        os.write("test".getBytes());
        os.close();
        client.completePendingCommand();

        if (dir != null)
        {
            if (!client.changeWorkingDirectory(dir))
            {
                throw new IllegalArgumentException("change dir to '" + dir + "' failed");
            }
        }

        System.err.println("System: " + client.getSystemName());

        FTPFile[] files = client.listFiles();
        for (int i = 0; i < files.length; i++)
        {
            FTPFile file = files[i];
            if (file == null)
            {
                System.err.println("#" + i + ": " + null);
            }
            else
            {
                System.err.println("#" + i + ": " + file.toString());
                System.err.println("\t name:" + file.getName());
            }
        }
        client.disconnect();
    }
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPClient

   */
  private void open(boolean force) throws XException
  {
    if ((!mOpen) || force)
    {
      mFTPClient = new FTPClient();

      /*
       * Connect to the FTP Server
       */
      Configuration config = Configuration.getInstance();
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPClient

    public FTPFile[] listFiles(String key, String relPath) throws IOException
    {
        try
        {
            updateLastAccessed();
          FTPClient client = getFtpClient();
          String dir = client.printWorkingDirectory();
          client.changeWorkingDirectory(relPath);
          FTPFile[] list = client.listFiles(key,null);
          client.changeWorkingDirectory(dir);
            return list;
        }
        catch (IOException e)
        {
            disconnect();
          FTPClient client = getFtpClient();
          String dir = client.printWorkingDirectory();
          client.changeWorkingDirectory(relPath);
          FTPFile[] list = client.listFiles(key,null);
          client.changeWorkingDirectory(dir);
            return list;
        }
        finally
        {
            updateLastAccessed();
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPClient

    public InputStream retrieveFileStream(String relPath, long restartOffset) throws IOException
    {
        try
        {
            FTPClient client = getFtpClient();
            client.setRestartOffset(restartOffset);
            return new InFilter(client.retrieveFileStream(relPath));
        }
        catch (IOException e)
        {
            disconnect();

            FTPClient client = getFtpClient();
            client.setRestartOffset(restartOffset);
            return new InFilter(client.retrieveFileStream(relPath));
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.