简体   繁体   中英

How to make FTPS data channel encrypted

I am new to FTP. I have a problem with my FTPSClient program. Only control channel is encrypted. I need both the control and data channel to be encrypted.

public boolean login(String usrName,char[] passwd){

    try {
        ftpClient = new FTPSClient(protocol,false); // SSL FTP
        ftpClient.connect(strHost);

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

        if (!FTPReply.isPositiveCompletion(reply)) {
            ftpClient.disconnect();
            log.error("FTP server refused connection.");
            return false;
        }

        ftpClient.setBufferSize(1000);

        if (!ftpClient.login(strUsrName,new String(passwd))){
            ftpClient.logout();
            bLoginStatus = false;
            return false;
        }
        else
            bLoginStatus = true;

        if(iMode == LOCAL_ACTIVE_MODE)
            ftpClient.enterLocalActiveMode();
        else if(iMode == LOCAL_PASSIVE_MODE)
            ftpClient.enterLocalPassiveMode();

    }  catch (SocketException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch(Throwable t){
        t.printStackTrace();
    }finally {
        if (bLoginStatus == false && ftpClient.isConnected()){
            try{
                ftpClient.disconnect();
            }
            catch (IOException f){
                // do nothing
            }
        }
    }

    if(ftpClient.isConnected())
        return true;
    else
        return false;
}

You need to tell the client to also encrypt the data connection, you can do this (if i recall correctly) with the PROT command:

client.execPBSZ(0);
client.execPROT("P");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM