Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.9k views
in Java FTP by (280 points)
Hi,

Could anyone tell me if there is any easier way to switch between SSL/TLS and normal FTP other than changing the code to establish a normal connection. Like enable or disable SSL/TLS using a flag?

Because if I turned off SSL/TLS in the server, the client( java code ) would still be expecting an SSL connection.

Thanks

3 Answers

0 votes
by (162k points)
Yes, you can use the CCC command to turn off SSL/TLS (see ccc() in SSLFTPClient) on the control channel.

Once off it can't be switched back on again.
0 votes
by (280 points)
Hi
I get an error as below when I include the ccc() command in my code. Not sure what I'm doing wrong?

FTPException caught connecting to localhost:21 (FTPThread.java-527)
com.enterprisedt.net.ftp.FTPException: 500 Syntax error, command unrecognized.
at com.enterprisedt.net.ftp.FTPControlSocket.validateReply(Unknown Source)
at com.enterprisedt.net.ftp.ssl.SSLFTPClient.ccc(Unknown Source)
at com.cypherit.bbrad.server.jobs.FTPThread.initialiseFTPConnection(FTPThread.java:483)
at com.cypherit.bbrad.server.jobs.FTPThread.run(FTPThread.java:667)



Code snippet where I have included the ccc() command:

ftp = new SSLFTPClient();
messageCollector = new FTPMessageCollector();
ftp.setMessageListener(messageCollector); // ensure that we get logging


ftp.setRemoteHost( recipientHost.getHostName() );

/* Set the timeout, if no timeout is specified in the ini file
* then set the timeout to 30 seconds
*/
if (bbRadConfig.getFTPTimeout() != -1)
ftp.setTimeout(bbRadConfig.getFTPTimeout());
else
ftp.setTimeout(30000);
ftp.setRemotePort( controlPort );

/*
* Validate server.
* The validator assumes commonName is set as hostname and validation fails
* if this does not match. You have to force the validator to check for a different
* commonName by passing the commonName variable.
*/
ftp.setValidateServer(false); // you can skip server validation by setting it to false. Default is true
if(commonName != null && !commonName.equals(""))
ftp.setCustomValidator(new SSLFTPStandardValidator(commonName));

ftp.getRootCertificateStore().importPEMFile(certificateFile);
ftp.connect();
ftp.auth(SSLFTPClient.AUTH_TLS);


if(!recipientHost.getProtocol().equals(RecipientHost.PROTOCOL_SSLTLSFTP))
{
ftp.ccc();
}


Thanks
Rashmi
0 votes
by (162k points)
Not all servers support the CCC command. It appears that yours doesn't.

Categories

...