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();
}
}
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();