使用commons-net连接到FTPS服务器时,“534策略需要SSL”

时间:2012-02-23 15:33:21

标签: java ftps apache-commons-net

我正在尝试使用commons-net库连接到FTPS服务器。我可以正常连接但是当我尝试列出文件时,我收到错误“534 Policy required SSL。”

import java.io.IOException;
import java.net.SocketException;

import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPSClient;
import org.apache.commons.net.util.TrustManagerUtils;

public class Test {

    public static void main(String[] args) throws SocketException, IOException {
        FTPSClient c = new FTPSClient("SSL", false);
        c.setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager());
        c.connect("10.10.6.225", 21);
        c.login("ftpuser", "Passw0rd");
        c.changeToParentDirectory();
        for (String s : c.getReplyStrings()) {
            System.out.println(s);
        }

        c.listFiles();
        for (String s : c.getReplyStrings()) {
            System.out.println(s);
        }
        for (FTPFile f : c.listFiles("/TestFolder")) {
            System.out.println("file");
            System.out.println(f.getName());
        }
        c.disconnect();
    }

}

1 个答案:

答案 0 :(得分:15)

登录后:

c.login("ftpuser", "Passw0rd");

尝试添加:

c.setFileType(FTP.BINARY_FILE_TYPE);
c.execPBSZ(0);  // Set protection buffer size
c.execPROT("P"); // Set data channel protection to private
c.enterLocalPassiveMode();