user2465852
user2465852

Reputation: 9

How I can call this function in another class?

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

Answers (1)

pogo2065
pogo2065

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

Related Questions