Sample code for 30+ languages & platforms
Java

Use Explicit FTP over TLS

See more FTP Examples

Demonstrates how to connect to an FTP server using explicit FTP over TLS.

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.your-ftp-server.com");
        ftp.setUsername("ftpAccountLogin");
        ftp.setPassword("ftpAccountPassword");

        // Indicate that the "AUTH TLS" command should be use to convert the connection to TLS
        // after the initial TCP connection to port 21 is established.
        ftp.setAuthTls(true);

        // Connect and convert the connection to TLS automatically.
        try {
            ftp.connectOnly();

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

        System.out.println("TLS connection established and successfully authenticated.");
    }
}