Q:

Connection reset with FTP/S java

I am trying to connect to my FTP server with FTP/S using simple java program. I am using JDK7u79 and Apache Commons Net 3.3.
I already had a look at similar questions here:
https://serverfault.com/questions/85027/how-do-i-setup-an-ftp-server-on-windows-7
FTPClient Uploading File = SocketException: Connection reset
Here is my connect() method:
/**
     * Connects and login to the FTP server
     */
    public void connect() throws IOException {
        int reply;
        FTPSClient ftpsclient = null;

        if(getFlavor().equalsIgnoreCase(FLAVOR_FTP)) {
            client = new FTPClient();   
        } else if(getFlavor().equalsIgnoreCase(FLAVOR_FTPS)) {
            client = new FTPSClient();
            //client = ftpsclient;
            ((FTPSClient) client).setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
        }

        try {
            client.connect(getHostname(), this.getPortInt());
        } catch (IOException ioe) {
            ioe.printStackTrace();
            String errMsg = "Could not connect to the FTP site. Reason: " + ioe.getMessage();
            throw new IOException(errMsg);
        }

        if(getFlavor().equalsIgnoreCase(FLAVOR_FTPS)) {
            ((FTPSClient) client).execPBSZ(0);  // Set protection buffer size
            ((FTPSClient) client).execPROT("P");    // Set data channel protection to private
        }

        if (ACTIVE_MODE.equalsIgnoreCase(getConnectionMode())){
            client.enterLocalActiveMode();
        }else if (PASSIVE_MODE.equalsIgnoreCase(getConnectionMode())){
            client.enterLocalPassiveMode();
        }

        // After connection attempt, you should check the reply code to verify success.
        reply = client.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            error("connect", "FTP server " + getHostname() + " refused connection.");
            throw new IOException("Failed to connect to FTP Server '" + getHostname() + "', Reply code '" + client.getReplyCode()+"'");
        }

        // login
        client.login(this.getLoginname(), this.getPassword());
        reply = client.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)){
            throw new IOException("Failed to login to FTP Server '" + getHostname() + "' using '"
                    + getLoginname() + "', Reply code '" + client.getReplyCode() + "'");
        }

        // mode change should be done only at connect()
        this.changeMode(this.getFileMode());

        // the same for server directory
        this.changeServerDirectory(this.getServerDirectory());
        reply = client.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)){
            disconnect();
            throw new IOException("Failed to change directory to [" + getServerDirectory() + "] on FTP Server [" + getHostname() + "]; Reply code=[" + client.getReplyCode() + "].");
        }

        message("Connect", "Successfully connected to FTP Server [" + getHostname() + "] using file mode=[" + getFileMode()+"]; Connection mode=[" + getConnectionModeString()+ "].");
    }

I get below exception always:
java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
    at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
    at sun.nio.cs.StreamDecoder.read(Unknown Source)
    at java.io.InputStreamReader.read(Unknown Source)
    at java.io.BufferedReader.fill(Unknown Source)
    at java.io.BufferedReader.read(Unknown Source)
    at org.apache.commons.net.io.CRLFLineReader.readLine(CRLFLineReader.java:58)
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:314)
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
    at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:400)
    at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:924)
    at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:207)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:183)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:203)
    at com.mycompany.FTPAdapter.connect(FTPAdapter.java:250)

I have tried out the executing following command as an adminstrator, but no luck:
netsh advfirewall set global StatefulFTP disable

I have created self-signed certificate using IIS on Windows 7. I can connect to the site using FTP/S through FileZilla. It asks me a prompt to trust the certificate and then it can connect to the server.
Can someone guide what am I doing wrong?

A:

Ah, I had to create FTPSClient with the parameter true: FTPSClient(true) as I am running FTP/S on default port 990.

