Sample code for 30+ languages & platforms
Java

Determine if Connected and Logged On

See more FTP Examples

The IsConnected property indicates whether or not the FTP component has a valid TCP/IP connection (and is logged on) to the FTP server.

Chilkat Java Downloads

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

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Ftp2 ftp = new Ftp2();

        ftp.setHostname("ftp.example.com");
        ftp.setUsername("mylogin");
        ftp.setPassword("mypassword");

        // Connect and login to the FTP server.
        try {
            ftp.connect();
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // ...

        // At any point in an FTP session, the IsConnected property
        // can be checked to determine if the component has remained
        // connected to the FTP server.
        if (ftp.getIsConnected()) {
            System.out.println("Connected!");
        } else {
            System.out.println("Not connected!");
        }

        // ...

        ftp.disconnect();
    }
}