java ftp关闭连接,当使用Java Apache FTPClient进行FTP TLS获取“握手期间远程主机关闭的连接”时,...

本文描述了使用Java Apache FTPClient在FTP TLS模式下遇到的"握手期间远程主机关闭的连接"错误。该问题在连接某些FTP服务器(如FileZilla Server)时发生,而连接其他服务器(如Microsoft FTP Service)则正常。解决方案是采用Cyberduck库,通过创建SSL上下文和自定义的信任管理器来处理仅允许单个会话的FTP服务器。
摘要由CSDN通过智能技术生成

I ran a Java (1.8) program on Windows 10 64x for FTP TLS (org.apache.commons.net.ftp):

FTPSClient ftpClient = new FTPSClient();

System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");

// LISTENER

ftpClient.addProtocolCommandListener(

new PrintCommandListener(new PrintWriter(System.out), true));

ftpClient.connect(server);

ftpClient.login(user, pass);

// Enter local passive mode

ftpClient.enterLocalPassiveMode();

// useEpsvWithIPv4

ftpClient.setUseEPSVwithIPv4(true);

// Set protection buffer size

ftpClient.execPBSZ(0);

// Set data channel protection to private

ftpClient.execPROT("P");

System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");

ftpClient.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());

ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

System.out.println("Remote system is " +

ftpClient.getEnabledCipherSuites());

System.out.println("SSL: " +

ftpClient.getEnableSessionCreation());

// PROTOCOLOS

String[] Protocols = ftpClient.getEnabledProtocols();

System.out.println("Protocols " + Protocols);

// AUTH

boolean Auth = ftpClient.getNeedClientAuth();

System.out.println("Auth: " + Auth);

ftpClient.getWantClientAuth();

ftpClient.getTrustManager();

ftpClient.feat();

// APPROACH #1: using retrieveFile(String, OutputStream)

String remoteFile1 = "/readme.txt";

File downloadFi

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值