Sample code for 30+ languages & platforms
Java

Get an FTP Listing Entry's Group

See more FTP Examples

Demonstrates the Chilkat Ftp2.GetGroup method, which returns the group name or identifier of a cached directory-listing entry. The only argument is a zero-based index. The value is empty when the server does not provide group metadata.

Background: The group is the counterpart to the owner in Unix-style ownership, driving the "group" permission bits. Like the owner, it is only present when the server's listing format includes it, and may be reported as a numeric GID. An empty value simply means the metadata was not provided.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Ftp2;

public class ChilkatExample {

    public static void main(String[] args) {
        // Demonstrates the Ftp2.GetGroup method, which returns the group name or identifier of a cached
        // directory-listing entry.  The only argument is a zero-based index.

        Ftp2 ftp = new Ftp2();

        ftp.setHostname("ftp.example.com");
        ftp.setUsername("myFtpLogin");

        // Normally you would not hard-code the password in source.  You should instead obtain it
        // from an interactive prompt, environment variable, or a secrets vault.
        ftp.setPassword("myPassword");

        try {
            ftp.connect();

            ftp.changeRemoteDir("public_html");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // GetDirCount retrieves the directory listing on the first call and returns the number of
        // entries.  A negative return indicates failure.
        int n = ftp.getDirCount();
        if (n < 0) {
            System.out.println(ftp.getLastErrorText());
            return;
        }

        for (int i = 0; i < n; i++) {
            String name = ftp.getFilename(i);

            // The group is empty when the server does not provide group metadata.
            String group = ftp.getGroup(i);
            System.out.println(group + "  " + name);
        }

        try {
            ftp.disconnect();
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }
    }
}