Pages Navigation Menu

Coding is much easier than you think

Listing System Help Using FTP

 

String listHelp() :This method retrieves the list of help information provided by the server and it returns the content in String. If there is no help information from the server then it will return null.

public String listHelp(String command) : Retrieves the help info from the ftp server for the specified command. Its return value in String.It returns null if there is no information.

command represents what you ask for help.

These methods throw FTPConnectionClosedException if server is closed before completion of operation and IOException, if there is any I/O error.

Example :

This example print the list of all the help info provided by the ftp server. We can list it by using FTPClient class method listHelp().

File : FtpHelpList.java

 

package com.simplecode.net;

import java.io.IOException;

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

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

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

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

			// Get List of system help

			System.out.println("System Help Information.... ");
			System.out.println(ftpClient.listHelp());

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