After you’ve established a connection you often want to read responses from the server. In order to be able to do so, the actual class needs to implement FTPListener. When that has been implemented you have a few methods that will give you more interraction with the FTP4CHE core. The below example strip away some of the useless information, and leaves the core of the reply in an arraylist.

Code

public class FTPResponse implements FTPListener {
 
	private ArrayList replies = new ArrayList();
 
	public void connectionStatusChanged(FTPEvent arg0) {}
 
	public void replyMessageArrived(FTPEvent event) {
		replies = new ArrayList();
		for (String e : event.getReply().getLines()) {
			if (!e.trim().equals("")) {
				e = e.substring(3).trim().replace("\n", "");
				if (!e.toUpperCase().contains("COMMAND SUCCESSFUL")) {
					e = e.substring(1).trim();
					replies.add(e);
				}
			}
		}
	}
 
	public ArrayList getReplies() {
		return replies;
	}
 
}
Donate using PayPal
If you found this publication useful to you, then feel free to show your appreaciation towards open-source publications by doing a small donation. It only takes a moment of your time. Any donation is appreaciated – and would also motivate me to release more as open-source. Donations so far – $0 USD – See previous donations.