This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Security and the fly likes FTPS / FTP over SSL with Jakarta Commons Net Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » Security
Bookmark "FTPS / FTP over SSL with Jakarta Commons Net" Watch "FTPS / FTP over SSL with Jakarta Commons Net" New topic
Author

FTPS / FTP over SSL with Jakarta Commons Net

T Inb
Greenhorn

Joined: Nov 26, 2009
Posts: 1
Hi,

I do not manage FTPS / FTP over SSL jet with 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();
}
}
}
 
GeeCON Prague 2014
 
subject: FTPS / FTP over SSL with Jakarta Commons Net