Reputation: 9
this is the MainActivity.Java. This function I want to call in another class
// Method to connect to FTP server:
public static boolean ftpConnect(String host, String username,
String password, int port) {
try {
mFTPClient = new FTPClient();
mFTPClient.connect(host, port);
if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
boolean status = mFTPClient.login(username, password);
mFTPClient.enterLocalPassiveMode();
mFTPClient
.setFileTransferMode(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
return status;
}
} catch (Exception e) {
Log.d(TAG, "Error: could not connect to host " + host);
}
return false;
}
Upvotes: 0
Views: 69
Reputation: 314
The general way to call these sorts of functions is to use the class name before the method.
Let's say that this method exists in a class called FTPHelper. To call this piece of code, you would use
FTPHelper.ftpConnect(host, username,password,port);
Upvotes: 1