如何使用java FTPSClient解决SSLHandshakeException?

时间:2017-04-26 08:20:40

标签: java ftps

我使用java FTPS客户端连接我的本地 FileZilla 服务器。但我的代码抛出 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(); } 。我该怎么办 ?帮我。

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

有什么问题?以下是我的错误日志。

(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.

这是服务器的日志。而Belows是我服务器的日志。

    $url = "myurl";

    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    $passwordStr = "$this->username:$this->password"; 
    curl_setopt($ch, CURLOPT_USERPWD, $passwordStr);

    curl_setopt($ch, CURLOPT_HTTPHEADER,
        array("Content-type: application/atom+xml"));

    $successCode = 200;

    $result = curl_exec($ch); 

0 个答案:

没有答案
相关问题