java.net.SocketException: Unconnected sockets not implemented FTPSClient

http://comments.gmane.org/gmane.comp.jakarta.commons.issues/10495

https://issues.apache.org/jira/browse/NET-327

Recently, the camel-ftp component was enhanced (on my request) with the possibility to use a secure data channel. This is accomplished by using the execProt() (and execPsbz()) method in class FTPSClient.

However, later on (in case Camel needs to reconnect), one of the connect() methods in the base class to FTPSClient is called. Unfortunately all the connect methods first create an unconnected socket and then tries to connect it. The connection factory now associated with the FTPSClient then throws an exception stating: "Unconnected sockets not implemented".

It seems like the FTPSClient does not support "re-connect" once it has entered secure communications mode.

See also: http://www.mail-archive.com/user@commons.apache.org/msg04933.html
and http://www.mail-archive.com/users@camel.apache.org/msg08732.html

 

 

Hide

Bogdan Drozdowski added a comment - 10/Mar/11 16:19

A code sample would be nice. But I've managed to do my own: executing the sequence "connect, execPROT(P), login, disconnect" twice on the same client instance causes the error. My patch fixes this issue - it overrides the disconnect() method of FTPClient in FTPSClient to re-set the SocketFactories (null is allowed, because the SocketClient knows how to deal with it). Thanks goes to Bengt Rodehav (http://www.mail-archive.com/user@commons.apache.org/msg04935.html) for pointing this out.

 

====

https://cn.forums.oracle.com/forums/thread.jspa?threadID=1531682

I had the same problem and fortunately, I have resolved it recently :-)

The key is you should write your own class which extends DefaultSocketFactory class and then set it to your FTPS client via method ftpsClient.setSocketFactory(yourSocketFactory);

In your socket factory class, remember to override the createSocket() method and it must return a new Socket, if not it will not work

@Override
public Socket createSocket() throws IOException {
return new Socket();
}

You might want to override the createSocket(host, port) method also to return a Socket with provided host and port.

Now you can use FTPS client to connect to FTPS server :-)

Hope this help. :-)

Regards,

Steven Nguyen

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值