Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

FTPS / FTP over SSL

843811Dec 1 2009
Hi,

I do not manage FTPS / FTP over SSL yet with Jakarta Commons Net.

See my code below. Executing it leads to this error:

Could not connect to server.
javax.net.ssl.SSLException: No available certificate or key corresponds to the SSL cipher suites which are enabled.
at com.sun.net.ssl.internal.ssl.SSLServerSocketImpl.checkEnabledSuites(SSLServerSocketImpl.java:307)
at com.sun.net.ssl.internal.ssl.SSLServerSocketImpl.accept(SSLServerSocketImpl.java:253)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:489)
at org.apache.commons.net.ftp.FTPSClient._openDataConnection_(FTPSClient.java:494)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2296)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2269)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2046)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2093)
at tests.ftps.CommonsNetFTPSTest.main(CommonsNetFTPSTest.java:68)
BUILD SUCCESSFUL (total time: 7 seconds)

FTPS with Filezilla works fine.
Connection details: FTP over implicit TLS / SSL
Any idea what exactly to do to get this code running?

Thorsten

---------------------------------------8<---------------------------------------

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;

public class CommonsNetFTPSTest
{
public static void main(String[] args) throws Exception
{
System.setProperty("javax.net.debug", "ssl");

String server = "server";
String username = "username";
String password = "password";
String remoteFile = "remotefile";
String localFile = "localfile";
String protocol = "TLS"; // TLS / SSL
int port = 990;
int timeoutInMillis = 3000;
boolean isImpicit = true;

FTPSClient client = new FTPSClient(protocol, isImpicit);

client.setDataTimeout(timeoutInMillis);
client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

try
{
int reply;

client.connect(server, port);

client.login(username, password);
client.setFileType(FTP.BINARY_FILE_TYPE);

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

System.out.println("Connected to " + server + ".");

reply = client.getReplyCode();

if (!FTPReply.isPositiveCompletion(reply))
{
client.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}

client.listFiles();

boolean retrieved = client.retrieveFile(remoteFile, new FileOutputStream(localFile));

}
catch (Exception e)
{

if (client.isConnected())
{
try
{
client.disconnect();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
System.err.println("Could not connect to server.");
e.printStackTrace();
return;
}
finally
{
System.out.println("# client disconnected");
client.disconnect();
}
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 29 2009
Added on Dec 1 2009
0 comments
1,817 views