4

I am trying to connect to an FTPS server using the commons-net library. I can connect properly but when I try to list the files, I get the error "534 Policy requires 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();
    }

}
approxiblue
  • 6,982
  • 16
  • 51
  • 59
sheu
  • 284
  • 5
  • 13

1 Answers1

20

After logging in:

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

try adding:

c.setFileType(FTP.BINARY_FILE_TYPE);
c.execPBSZ(0);  // Set protection buffer size
c.execPROT("P"); // Set data channel protection to private
c.enterLocalPassiveMode();
approxiblue
  • 6,982
  • 16
  • 51
  • 59
TC Kuang
  • 224
  • 3
  • 3
  • 1
    thank you TC , my problem is same this and resolved, but my app worked for 6 month but in last week stoped with "534 Policy requires SSL." during storeFile, why reason of this ? is related to network configurations ? – Saeed Aliakbari Jun 18 '18 at 08:35
  • @tc-kuang Even I get the reply "534 Policy requires SSL" when storing file. Can you please elaborate what execPBSZ(0) and execPROT("P") do? – Gagan T K Apr 01 '22 at 04:35