Pages Navigation Menu

Coding is much easier than you think

Get Buffer size on FTP Server

 

You can find out the current internal buffer size for your data socket by using the FTPClient class method.

int getBufferSize() : This method returns int value. It fetches the present internal buffer size for your data sockets.

Example :

Here is an example to print the internal buffer size for our data socket.For that we are calling method client.getBufferSize().

File : FtpGetBufferSize.java
 

package com.simplecode.net;

import java.io.IOException;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPConnectionClosedException;

class FtpGetBufferSize {
	public static void main(String[] args) throws IOException {
		FTPClient client = new FTPClient();
		boolean result;
		try {
			// Connect to the localhost
			client.connect("localhost");

			// login to ftp server
			result = client.login("admin", "admin");

			if (result == true) {
				System.out.println("User logged in successfully !");
			} else {
				System.out.println("Login failed!");
				return;
			}

			// Get buffer size
			System.out.println("Current Buffer size : "
					+ client.getBufferSize());

		} catch (FTPConnectionClosedException e) {
			System.err.println(e);
		} finally {
			try {
				client.disconnect();
			} catch (FTPConnectionClosedException e) {
				System.err.println(e);
			}
		}
	}
}