1

I used java FTPS Client to connect my local FileZilla Server. But My code throw SSLHandshakeException. How do I do ? Help me.

 public void doSend(String url, String port, String user, String password, File file, String fileName) throws IOException {
    String remote = fileName;
    FTPSClient client = new FTPSClient();
    client.setAuthValue("TLS");
    client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
    client.setRemoteVerificationEnabled(false);

    InputStream input = new BufferedInputStream(new FileInputStream(file));
    InetAddress inetAddress = Inet4Address.getLocalHost();
    client.connect(inetAddress, Integer.parseInt(port));
    client.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());

    int reply;
    reply = client.getReplyCode();

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

    client.login(user, password);

    client.setBufferSize(1000);
    client.enterLocalPassiveMode();
    client.setFileType(FTP.BINARY_FILE_TYPE);
    client.execPBSZ(0);
    client.execPROT("P");
    client.enterLocalPassiveMode();
    client.storeFile(remote, input);   //it cause exception
    client.logout();
}

What is problem? The below is my error log.

Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:980)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1363)
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:735)
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at java.io.FilterOutputStream.close(FilterOutputStream.java:158)
at org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:593)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:557)
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1795)
at FTPSClientManager.doSend(FTPSClientManager.java:50)
at FTPSClientManager.main(FTPSClientManager.java:16)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:505)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:961)
... 11 more

This is Server's log. And Belows are my server's log.

(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> 230 Logged on
(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> TYPE I
(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> 200 Type set to I
(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> PBSZ 0
(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> 200 PBSZ=0
 (000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> PROT P
(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> 200 Protection level 
set to P
(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> PASV
(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> 227 Entering Passive 
Mode (192,168,56,1,233,30)
(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> STOR temp.txt
(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> 150 Opening data    
channel for file upload to server of "/temp.txt"
(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> 450 TLS session of 
data connection has not resumed or the session does not match the control 
connection
(000047)2017-04-26 오후 17:12:33 - admin (192.168.56.1)> disconnected.
Castaglia
  • 2,972
  • 5
  • 28
  • 49
  • Add the complete stacktrace – Jens Apr 26 '17 at 08:22
  • You might see if [this FileZilla forum post](https://forum.filezilla-project.org/viewtopic.php?t=36903), talking similar issues and FileZilla's "Require TLC session resumption on data connection" configuration, might help. – Castaglia May 09 '17 at 15:08
  • i have solved this using cyberduck library please refer this link https://stackoverflow.com/questions/46631315/when-using-java-apache-ftpclient-for-ftp-tls-getting-remote-host-closed-connect/48616779#48616779 – Dhiraj Pandit Feb 12 '18 at 07:04

0 Answers0