Java Code Examples for org.apache.commons.net.ftp.FTPSClient#disconnect()

The following examples show how to use org.apache.commons.net.ftp.FTPSClient#disconnect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultipleConnectionTestCase.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnderlyingConnect() throws SocketException, IOException {
    final FTPSClient client1 = this.init(new FTPSClient(true));
    final FTPSClient client2 = this.init(new FTPSClient(true));
    try {
        final String hostname = "localhost";
        client1.connect(hostname, AbstractFtpsProviderTestCase.getSocketPort());
        client2.connect(hostname, AbstractFtpsProviderTestCase.getSocketPort());
    } finally {
        if (client1 != null) {
            client1.disconnect();
        }
        if (client2 != null) {
            client2.disconnect();
        }
    }
}
 
Example 2
Source File: ConnectionStressTest.java    From drftpd with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    try {
        FTPSClient c = new FTPSClient();
        c.configure(ftpConfig);

        logger.debug("Trying to connect");
        c.connect("127.0.0.1", 2121);
        logger.debug("Connected");

        c.setSoTimeout(5000);

        if (!FTPReply.isPositiveCompletion(c.getReplyCode())) {
            logger.debug("Houston, we have a problem. D/C");
            c.disconnect();
            throw new Exception();
        }

        if (c.login("drftpd", "drftpd")) {
            logger.debug("Logged-in, now waiting 5 secs and kill the thread.");
            _sc.addSuccess();
            Thread.sleep(5000);
            c.disconnect();
        } else {
            logger.debug("Login failed, D/C!");
            throw new Exception();
        }
    } catch (Exception e) {
        logger.debug(e, e);
        _sc.addFailure();
    }

    logger.debug("exiting");
}
 
Example 3
Source File: FTPUtils.java    From TranskribusCore with GNU General Public License v3.0 5 votes vote down vote up
public static void connectToFTP(FTPSClient ftp, String ftpServer, int ftpPort) throws SocketException, IOException {
	ftp.connect(ftpServer, ftpPort);
	// After connection attempt, you should check the reply code to verify
	// success.
	int reply = ftp.getReplyCode();

	if (!FTPReply.isPositiveCompletion(reply)) {
		ftp.disconnect();
		throw new IOException("FTP server refused connection, reply code: " + reply);
	}
	logger.debug("Connected to " + ftpServer + "."+ftp.getReplyString());
}
 
Example 4
Source File: ConnectionStressTest.java    From drftpd with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    try {
        FTPSClient c = new FTPSClient();
        c.configure(ftpConfig);

        logger.debug("Trying to connect");
        c.connect("127.0.0.1", 2121);
        logger.debug("Connected");

        c.setSoTimeout(5000);

        if (!FTPReply.isPositiveCompletion(c.getReplyCode())) {
            logger.debug("Houston, we have a problem. D/C");
            c.disconnect();
            throw new Exception();
        }

        if (c.login("drftpd", "drftpd")) {
            logger.debug("Logged-in, now waiting 5 secs and kill the thread.");
            _sc.addSuccess();
            Thread.sleep(5000);
            c.disconnect();
        } else {
            logger.debug("Login failed, D/C!");
            throw new Exception();
        }
    } catch (Exception e) {
        logger.debug(e, e);
        _sc.addFailure();
    }

    logger.debug("exiting");
}